# Large braces over several items in an itemize with text by the brace

This question is related to this question: Adding large brace next to body text, but is not a duplicate.

I have an itemize in a beamer presentation. I want to put a brace over some of these items. So here's what I have so far:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\begin{document}
\begin{frame}
\frametitle{Here is text}
\begin{itemize}[<+->]
\item A first item \tikzmark{topbrace}
\item Another item, also inside the brace \tikzmark{bottombrace}\tikzmark{right}
\item Outside the brace
\end{itemize}
\onslide<+->{
\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={brace,amplitude=0.5em},decorate,ultra thick,black]
($(right)!(topbrace.north)!($(right)-(0,1)$)$) --  ($(right)!(bottombrace.south)!($(right)-(0,1)$)$);
\end{tikzpicture}
}
\end{frame}
\end{document}


(needs compiling twice to get the right result). Incidentally, why is this? Is it something to do with the remember picture thing?

I have two issues with this excellent solution: the spacing doesn't look right (I'd like the top of the brace to be higher), and I'd like to add text to the right of the brace (see picture).

I can't quite fathom the complicated positioning commands used to add an extra node with text, or modify the spacing...

What I'd really like from an answer to this question is an explanation of what the ! and $ are doing... - Have you tried just adding node[pos=0.5,anchor=left] {I'd like some text here} before the semicolon in your \draw statement? – Matthew Leingang Mar 1 '11 at 13:57 @Matthew s/left/west/ yes. That works, although the spacing needs some work. – Seamus Mar 1 '11 at 14:05 remember picture needs two compiles. On the first compile TikZ has to gather the positions on the second compile it uses them. Same problem as with references. – Caramdir Mar 1 '11 at 17:11 ## 3 Answers These symbols are used for coordinate calculations. You need to load the library calc with \usetikzlibrary{calc} in order to use the coordinate calculation functions \documentclass{scrartcl} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \draw [help lines] (0,0) grid (5,3); \path coordinate (a) at (1,1) coordinate (b) at (5,3) coordinate (c) at (2,3); \fill [blue] (a) circle (2pt); \fill [green] (b) circle (2pt); \fill [red] ($(a) + 2*(1,1)$) circle (2pt); \fill [purple] ($(a)!-.5!(b)$) circle (2pt); \coordinate (d) at ($(a)!(c)!(b)$); \fill [black] (c) circle (2pt) (d) circle (2pt); \draw (c) -- (d); \end{tikzpicture} \end{document}  1. How to use $: As you can see, the syntax uses the TEX math symbol $ to indicate that a “mathematical computation”. The red circle is placed from (a). I add 2*(1,1) at the coordinates of (a) so I get 1+2 and 1+2 (it's like addition of vectors) 2. How to use !: I want to get a coordinate of point between (a) and (b). If I want the middle I use ($(a)!.5!(b)$). I use (...) to search coordinates. Then I use $..$ to make a calculation. Finally, I use !number! to get a point on the line (a)--(b). It's like to use pos =.5. - Oh! So foo!.5!bar works quite similarly to that construction in xcolor colour specifications, except that it uses fractions rather than percentages. Neat. – Seamus Mar 1 '11 at 13:34 @Seamus: you can also use number > 1 and you can use negative number for example ($(a)!-.5!(b)$) or ($(a)!25!(b)$) . It's like a barycenter. – Alain Matthes Mar 1 '11 at 13:46 @Altermundus it seems that the ! can also have the name of a node in the middle (see example in question). What does this mean? – Seamus Mar 1 '11 at 13:50 @Seamus: I update my answer : it's more complicated. When you write ($(a)!(c)!(b)$) you use a projection modifier. It also gives a point on a line from the ⟨first coordinate⟩ to the ⟨second coordinate⟩. However, the ⟨number⟩ or ⟨dimension⟩ is replaced by a ⟨projection coordinate ⟩. In my example, (d) is the orthogonal projection of (c) on the line (a)--(b). The result is always a point of (a)--(b). – Alain Matthes Mar 1 '11 at 14:07 @Altermundus: I've tried to mark you inline code with backticks . However, since I don't fully understand your answer, I'm not sure if I did it correctly. In particular, I don't quite understand the sequence of "because"s in #2. – Hendrik Vogt Mar 1 '11 at 14:15 Another TikZ answer. I think using the let operation makes the code a bit easier to parse. It also saves you from having to use declare the right anchor. \documentclass{beamer} \usepackage{tikz} \usetikzlibrary{decorations.pathreplacing,calc} \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};} \begin{document} \begin{frame} \frametitle{Here is text} \begin{itemize}[<+->] \item A first item \tikzmark{topbrace} \item Another item, also inside the brace \tikzmark{bottombrace} \item Outside the brace \end{itemize} \onslide<+->{ \begin{tikzpicture}[overlay, remember picture] \draw [decoration={brace,amplitude=0.5em},decorate,ultra thick,black] let \p1=(topbrace), \p2=(bottombrace) in ({max(\x1,\x2)}, {\y1+0.8em}) -- node[right=0.6em] {I'd like some text here} ({max(\x1,\x2)}, {\y2}); \end{tikzpicture} } \end{frame} \end{document}  After let \p1=(topbrace), one can access its x and y coordinates with \x1 and \y1. So it is easier to find the right place for the brace (note that the anchors are placed on the baseline, hence the +0.8em in the top point). If you place a node immediately after -- it is place in the middle of the line. We want it to be a bit to the right of that. - That is clever. I was just thinking that Andrew Stacey's solution to the original question would be a lot easier if you didn't have to do the projecting on to the right node and instead you could just fetch the x coordinates of each anchor. Very nice! – Seamus Mar 1 '11 at 17:39 I think @Altermundus gave an excellent description of what was going on in Andrew's earlier answer, so I think I will accept that answer. However, I think this is a better solution to the original problem I linked to in my question... – Seamus Mar 1 '11 at 17:40 @Seamus, I was planning to add that to my answer to the linked question, but had to leave. I'll do that later. – Caramdir Mar 1 '11 at 19:03 @Seamus: Thinking through that once more, I realized that this solution stops working when putting a brace from the first to the third line in the example (as the longer second line is not taken into account). But you can change the first point in Andrew's code to something like ($(right)!(topbrace.north)!($(right)-(0,1)$) + (0,0.8em)$) and add a node in the same position as in my example. – Caramdir Mar 2 '11 at 2:01 \documentclass{beamer} \usepackage{picture} \begin{document} \begin{frame}{Here is text} \begin{itemize}[<+->] \item A first item \item Another item, also inside the brace \makebox(0,0){\put(0,2.2\normalbaselineskip){%$\left.\rule{0pt}{1.1\normalbaselineskip}\right\}\$ foo}}
\item Outside the brace
\end{itemize}
\end{frame}
\end{document}
`

-
This is a nice solution. However: I think the TikZ solution I'm trying to modify is easier to manipulate (adding an extra item in the braces would work without modification) and also I'm more interested in learning about TikZ than I am to the solution of the actual problem itself. –  Seamus Mar 1 '11 at 14:02
I see, you like to shoot with canon balls on sparrows ... –  Herbert Mar 1 '11 at 14:05
as a way of learning how to use canons, it's good practice. –  Seamus Mar 1 '11 at 14:38