78

I'm writing a short document listing some chronological events. I want to pick out a period with a big brace. Here's a quick mockup:

alt text

What's the best way to do this? Can I set the size declaratively - ie from line A to line B - somehow?

diabonas
  • 25,784
  • 1
    Although it might not be best for your particular situation: Unicode provides for characters that are just the top of the brace, the bottom, and the middle. They can be connected with vertical lines of whatever length is necessary. Then, the resulting composite brace is as tall as it needs to be, but without being heavier in weight. Not specific to TeX. Of course, hardly any fonts have these characters. –  Feb 23 '17 at 18:43
  • @RobtA seems awesome! what are the characters (top of the brace, the bottom, and the middle)? oops, found it: discover your character – nilon Apr 29 '17 at 07:48

7 Answers7

81

As this is one of the initial, and therefore most visible, incarnations of \tikzmark, I thought it a good idea to update it to an answer using the \tikzmark library.

\documentclass{article}
%\url{https://tex.stackexchange.com/a/1570/86}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc,tikzmark}

\begin{document}

\hfill\tikzmark{right}
\begin{itemize}
\item First line
\item Second line \tikzmark{2nd}
\item Third line, which is quite long and seemingly tedious in the extreme
\item Fourth line, which isn't as long as the third \tikzmark{4th}
\item Fifth line
\end{itemize}

\begin{tikzpicture}[overlay, remember picture]
\node[anchor=base] (a) at (pic cs:2nd) {\vphantom{h}}; % push the mark to the top of the line (ie including ascenders)
\node[anchor=base] (b) at (pic cs:4th) {\vphantom{g}}; % push the mark to the bottom of the line (ie including descenders)
\draw [decoration={brace,amplitude=0.5em},decorate,ultra thick,gray]
 (a.north -| {pic cs:right}) -- (b.south -| {pic cs:right});
\end{tikzpicture}
\end{document}

braces next to text


Original Answer

I'd seriously suggest using tikz for this. Here's an alternative to Caramdir's (excellent) solution:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\begin{document}

\hfill\tikzmark{right}
\begin{itemize}
\item First line
\item Second line \tikzmark{2nd}
\item Third line, which is quite long and seemingly tedious in the extreme
\item Fourth line, which isn't as long as the third \tikzmark{4th}
\item Fifth line
\end{itemize}

\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={brace,amplitude=0.5em},decorate,ultra thick,gray]
 ($(right)!(2nd.north)!($(right)-(0,1)$)$) --  ($(right)!(4th.south)!($(right)-(0,1)$)$);
\end{tikzpicture}
\end{document}

What I like about this one is that it doesn't mess around with how the actual data is put in, the decoration is added afterwards almost as an afterthought, which (to me) fits in better with the feel of what you're trying to do.

What isn't so good is the placement of the brace horizontally. Because I don't know how your are typesetting your data, nor what sort of data it is, I've just shoved the brace to the right-hand side. If your data is more structured, as the graphic suggests, then it would be easy to make it appear in the right place. (Indeed, from experimenting, I'd say that if your data isn't nicely structured - by which I mean that the lines should be of similar widths - then a brace at the right-hand side doesn't look good as it's not easy to see exactly which lines it is including or excluding.)

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
  • 6
    That \tikzmark macro is a good idea, I have to remember that. – Caramdir Aug 11 '10 at 21:00
  • I think the result looks nicer if the tikzmark places its not slightly above the baseline: \node at (0,0.7ex) (#1)... – Seamus Mar 01 '11 at 14:37
  • @Seamus: Since I answered this, I've changed my way of doing it. I now place a \vphantom{X} in the node which makes it better placed. (Actually, I have \tikzmarkX which does this, and various other variants .. but you just knew that I'd have a more complicated scheme, didn't you!) – Andrew Stacey Mar 01 '11 at 18:11
  • 7
    Why \node (#1) {};? \coordinate (#1); would be better. It avoids border issues with (name) versus (name.center) etc. – Martin Scharrer Jun 24 '11 at 12:20
  • @AndrewStacey - I have similar need and it works fine for one page but the bracket does not travel to next page. If I create start and end spanning two pages then entire bracket appears on the second page. Is it possible to create a bracket that can span across pages. Thanks for your help – Raama Oct 25 '12 at 16:35
  • 1
    @Raama Given that this is quite an old question and that that change would need a few bits that I'm not sure how to do, I think that's worth asking as a new question (refer back to this one, of course). – Andrew Stacey Oct 25 '12 at 16:37
  • Maybe note that there is now a library for this? ;) – cfr Dec 12 '14 at 01:40
  • @cfr Is there? What library is that? (Please provide a link rather than a hint!) – Andrew Stacey Dec 12 '14 at 22:32
  • @cfr Having actually just read the answer again, I realise you might be referring to the infamous tikzmark library rather than a library to put braces next to text (as I originally thought). Are you? – Andrew Stacey Dec 12 '14 at 22:34
  • @LoopSpace Yes, I did have that library in mind ;). (I was not trying to be obscure!) – cfr Dec 12 '14 at 22:53
  • Can I ask what does ($(right)!(2nd.north)!($(right)-(0,1)$)$) mean in your code? I want to adjust it for myself but I have no idea what it does. – m0_as Feb 15 '18 at 17:41
  • @m0_as That's a calc expression. Your best bet would be to read the section of the TikZ manual about such expressions (given that this answer was written over 7 years ago, I'm not able to reconstruct my thinking). Also, the version of \tikzmark given here has evolved considerably over the years so you should focus your attention on the answer given to your new question. – Andrew Stacey Feb 15 '18 at 19:17
  • Whoa! I just got a down-vote on this question. I doubt the down-voter will see this comment, but would they care to explain their vote? I don't mind the vote, but I'd like to know what I could do to improve the answer. – Andrew Stacey Feb 15 '18 at 23:20
  • Maybe the downvoter was just resentful that your answer has so many more upvotes than the accepted answer? Anyhow, I myself had never seen this before, so I have an available upvote for you. Here. – Harald Hanche-Olsen Feb 16 '18 at 07:24
  • @LoopSpace thanks for all this! how do I reverse the curly bracket? I want to be on the left and pointing to the left like this "{". Thanks! – Rollo99 Jan 18 '20 at 22:05
  • 1
    @Rollo99 simplest way is to draw it in the opposite direction, so specify the coordinates in the other order. Or I think you can use a negative amplitude, check the tikz documentation on that one. – Andrew Stacey Jan 19 '20 at 15:14
  • I want to add some text too (in vertical position) Can you please tell me. In my case arrows are on left side of bullets – user3582228 Jun 12 '21 at 17:03
  • @user3582228 you can add nodes into the tikzpicture environment that draws the brace and so include text at various positions. If you're not sure how to do that it would probably be better to ask a new question to get the best help. – Andrew Stacey Jun 12 '21 at 18:37
29

I suggest a variation of Giel's answer with tabular

$\left.\begin{tabular}{l}
line \\
one more line
\end{tabular}\right\}$

(or smth like {tabular}{p{5cm}} if you need not a couple of short lines but a paragraph inside the tabular).

Grigory M
  • 4,984
  • 4
  • 39
  • 37
  • 1
    Good idea. To span more rows, use \parbox instead of tabular. $\left. \parbox{\linewidth}{\lipsum[1]} ,\right} \textrm{Title}$. Note: \lipsum[1] is a dummy text from lipsum.sty package. – Display Name Nov 27 '10 at 14:10
26

A simpler solution:

\documentclass{article}
\usepackage{lipsum}
\usepackage{schemata}
\begin{document}
\lipsum[1]
\schema[close]{\lipsum[2]}{}
\lipsum[3]
\end{document}

MWE

Fran
  • 80,769
  • 4
    A very elegant solution. It's worth mentioning that the second argument can be used to place text in the margin, i.e. \schema[close]{body text}{margin text} – onewhaleid Jul 22 '14 at 23:33
21

Just for fun an answer using TikZ:

\usetikzlibrary{matrix,decorations.pathreplacing}

\begin{tikzpicture}
    \matrix (m) [matrix of nodes,column 1/.style={anchor=west}]
    {
    The first line. \\
    The second line. \\
    A very long third line that goes on. \\
    A fourth line. \\
    And finally a last line. \\
    };

    \draw [decoration={brace,amplitude=0.5em},decorate,ultra thick,gray]
        (m-2-1.north -| m.east) -- (m-4-1.south -| m.east);
\end{tikzpicture}

example rendering

To specify from which row to which row the brace should go change m-2-1 and m-4-1 accordingly (the second number is always the row). To change thickness and color, change the ultra thick and gray parts (see section 14.3 of the TikZ manual). To add a text to the right of the brace change -- to -- node[black, right=0.7em] {some text}. The amplitude option defines how much the brace extends and you can add ,aspect=factor (with factor replaced by a number between 0 and 1) to specify where the pointy part lies on the brace (see section 27.3). Changing anchor=west to anchor=east make the lines right aligned, removing it centers them.

Werner
  • 603,163
Caramdir
  • 89,023
  • 26
  • 255
  • 291
  • Additional question: if I want some further text to the right of the brace, could you say how to do it? (The idea is that in the document I'm trying to typeset, a bunch of lines need to be collected together with a brace and some text like "and their spouses" on the right of the brace.) I could ask a new question, but if the answer is a trivial variation of this, it would pretty much be a duplication. – ShreevatsaR Oct 26 '11 at 16:55
  • @ShreevatsaR: Simply replace -- in the \draw command by -- node[right=1em] {and their spouses} (adjust the 1em to whatever distance looks good for your text). Exactly the same also works for Andrew's solution. – Caramdir Oct 26 '11 at 23:16
10

In mathmode you could use some trickery like putting a matrix to the left of a \right}, e.g.:

\documentclass{article}

\begin{document}

\begin{displaymath}
    \left. \begin{array}{cc}
        - & - \\
        - & - \\
        - & -
    \end{array} \right\}
\end{displaymath}

\end{document}
Giel
  • 1,753
  • Ooh, actually this works nicely, though I'm not sure how it will copy with a body of text. I might also be able to use \cases in an unconventional way... – Internet man Aug 11 '10 at 19:51
  • @tex-offender you can wrap bodies of text in an \mbox{}, within that box text is rendered in normal (i.e. non-math) mode – Giel Aug 13 '10 at 21:29
7

Here's an implementation that gives the output of Andrew Stacey's excellent (and very famous) tikzmark idea but using the tcolorbox package.

screenshot

As you can see, it allows page breaks, although the brace is repeated across pages.

% arara: pdflatex
% !arara: indent: {overwrite: on}
\documentclass{article}

\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\usetikzlibrary{decorations.pathreplacing}

\newtcolorbox{rightbrace}{%
    enhanced jigsaw, 
    breakable, % allow page breaks
    frame hidden, % hide the default frame
    overlay={%
        \draw [
            fill=none, % fill paper
            decoration={brace,amplitude=0.5em},
            decorate,
            ultra thick,
            gray,
        ]
        % right line
        (frame.north east)--(frame.south east);
    },
    % paragraph skips obeyed within tcolorbox
    parbox=false,
}

\begin{document}

\begin{itemize}
    \item First line
          \begin{rightbrace}
            \item Second line 
            \item Third line, which is quite long and seemingly tedious in the extreme
            \item Fourth line, which isn't as long as the third 
          \end{rightbrace}
    \item Fifth line
\end{itemize}

\begin{rightbrace}
    \lipsum[1]
\end{rightbrace}
\lipsum[2]

\end{document}
cmhughes
  • 100,947
6

You can use pstricks-add.sty as follows: (details can be found here on page 18)

\documentclass{article}

\usepackage{pstricks-add}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\par\noindent%
\begin{minipage}{0.99\linewidth}%adjust if necessary
\noindent\hfill\rnode{A}{}~
\par
\vspace*{-0.5ex}%adjust if necessary
\lipsum[1]
\vspace*{-2ex}%adjust if necessary
\noindent\hfill\hspace{5mm}\rnode{B}{}~%
\psbrace[linecolor=red,ref=lC](B)(A){Important!}
\end{minipage}
\par
\lipsum[1]
\end{document}

This is the output:

alt text

Display Name
  • 46,933