tags:

views:

260

answers:

1

This question resulted from the question here

I want to produce a curly brace which spans some lines of text. The problem is that I have to align the x coordinate manually, which is not a clean solution.

Currently I use

\begin{frame}{Example}

\begin{itemize}
\item The long Issue 1
\tikz[remember picture] \node[coordinate,yshift=0.7em] (n1) {}; \\
spanning 2 lines


\item Issue 2
  \tikz[remember picture] \node[coordinate, xshift=1.597cm] (n2) {};
\item Issue 3

\end{itemize}

\visible<2->{
\begin{tikzpicture}[overlay,remember picture]
  \draw[thick,decorate,decoration={brace,amplitude=5pt}]
        (n1) -- (n2) node[midway, right=4pt] {One and two are cool};
\end{tikzpicture}
 } % end visible

\end{frame}

which produces the desired result:

tikz example1

The unsatisfying thing is, that I had to figure out the xshift value of 1.597cm by trial and error (more or less)

Without xshift argument the result is:

tikz example 1

I guess there is an elegant way to avoid the explicit xshift value.

The best way would it imho be to calculate the maximum x value of two nodes and use this, (as already suggested by Geoff)

But it would already be very handy to be able to explicitly define the absolute xvalues of both nodes while keeping their current y values. This would avoid the fiddly procedure of adapting the third post decimal position to ensure that the brace looks vertical.

+3  A: 

This requires \usetikzlibrary{calc}. There may be a cleaner way, though.

Remove the "xshift" from node n2 and then use:

\begin{tikzpicture}[overlay,remember picture]
  \path (n2) -| node[coordinate] (n3) {} (n1);
  \draw[thick,decorate,decoration={brace,amplitude=5pt}]
        (n1) -- (n3);
  \node[right=4pt] at ($(n1)!0.5!(n3)$) {One and two are cool};
\end{tikzpicture}
ESultanik
Actually, I don't think you need calc. You can use the same line as presented by basweber, but just put (n3) instead of (n2). The key in this answer is defining the turning point of the rectilinear path (n3). Good call!
Geoff
I tried using the original code (with "midpoint") but for some reason that ended up putting the node at the bottom of the brace (at the same y-coordinate as n2). I am not sure why that was the case.
ESultanik
@ESultanik: Thank you very much. It works and its a clean solution.@Geoff: You are right: ($(n1)!0.5!(n3)$) (and hence calc) is not needed. On my machine the two versions produce the same result. Thanks for pointing that out.
basweber