27

I’m trying to typeset a table of data, with brackets (i.e. }) at the right-hand side to show a classification of the rows.  Something like:

-----------------------
| Aardvark | Armenia  |  \
|----------|----------|  |- things beginning with vowels 
| Elephant | Ethiopia |  /
|----------|----------|
| Platypus | Portugal |  \
|----------|----------|  |- things beginning with consonants
| Zebra    | Zimbabwe |  /
-----------------------

The main data is in a tabular environment.  Is there a nice way to put the brackets on the right like this, aligned correctly with the rows?

Edit: if possible, I’d really prefer an approach which doesn’t interfere with how the table of data itself comes out.

3
  • 2
    check out the bigdelims package (part of multirow) - Apr 8, 2011 at 2:59
  • 1
    You could also adapt this code, although that's probably overkill...
    – Seamus
    Apr 8, 2011 at 8:08
  • @prettygully: That looks like just the ticket! If you put it in an answer, I’ll accept it. @Seamus: hmm, that’s very nice — probably overkill here as you say, but I‘ll remember it for the future. Apr 8, 2011 at 16:05

5 Answers 5

26

You can use bigdelim from multirow to achieve this:

\documentclass{minimal}
\usepackage{multirow,bigdelim}
\begin{document}
\begin{tabular}{lll}
Aardvark & Armenia & \rdelim\}{2}{3mm}[things beginning with vowels] \\
Elephant & Ethiopia \\
Platypus & Portugal & \rdelim\}{2}{3mm}[things beginning with consonants] \\
Zebra  & Zimbabwe \\
text  & text & \rdelim\}{3}{3mm}[things beginning and ending with t] \\
text  & text \\
text  & text \\
\end{tabular} 
\end{document}
8

One possible solution would be to nest tabular and array environments; in the following example I used a tabular with two columns; the first column will contain the tabular with the data and the second column will contain an array for the extensible braces and the text for the classification of the rows.

I also defined a command \MyLBrace (with two arguments) to typeset the brace; the first argument controls the height of the brace and the second one contains the text corresponding to the particular category; since the number of rows belonging to the same category is variable, some manual calculation will be needed to adjust the height of the braces.

A little example:

\documentclass{book}
\usepackage{amsmath}

\newcommand\MyLBrace[2]{%
  \left.\rule{0pt}{#1}\right\}\text{#2}}

\begin{document}

\noindent\begin{tabular}{c@{}l}
  \begin{tabular}{ll@{}}
    Aardvark & Armenia \\
    Elephant & Ethiopia \\
    Platypus & Portugal \\
    Zebra  & Zimbabwe \\
    text  & text \\
    text  & text \\
    text  & text \\
  \end{tabular} 
  & 
  $\begin{array}{l}
    \MyLBrace{3ex}{things beginning with vowels} \\ 
    \MyLBrace{3ex}{things beginning with consonants} \\
    \MyLBrace{4.4ex}{things beginning and ending with t} 
  \end{array}$
\end{tabular}

\end{document}

1
  • ah, neat — a very nice “low-TeX” solution! I’ll probably go for bigdelims in the end as per @prettygully’s comment, but if that didn’t exist I’d definitely be going for this one. Apr 8, 2011 at 16:10
6
\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{tabular}{@{}l}
  $\left.
  \begin{tabular}{@{}*2{p{1.5cm}}}
    Aardvark & Armenia \\
    Elephant & Ethiopia 
  \end{tabular}
  \right\}\text{things beginning with vowels}$\\[\bigskipamount]
%
  $\left.
  \begin{tabular}{@{}*2{p{1.5cm}}}
    Platypus & Portugal \\
    Zebra  & Zimbabwe
  \end{tabular}
  \right\}\text{things beginning with consonants}$
\end{tabular}

\end{document}

enter image description here

1
  • 2
    Thankyou — unfortunately this breaks up the structure of the table itself, which I really don’t want to do. Apr 8, 2011 at 15:57
4

Here's an expansion upon prettygully's answer that lets you have line breaks and defines a new command for it:

\newcommand\multibrace[3]{\rdelim\}{#1}{3mm}[\pbox{#2}{#3}]}

\begin{table}[h!]
  \centering
  \begin{tabularx}{0.75\textwidth}{>{$}l<{$} l l}
    \text{Complexity} & Growth rate \\ \cline{1-2}
    O(1)              & None\\
    O(log n)          & Logarithmic\\
    O(n^k)            & Polynomial\\
    O(n)              & Linear & \multibrace{3}{4.6cm}{
                                  All of these are special cases of polynomials,
                                  $n^1, n^2$ and $n^3$ respectively
                                } \\
    O(n^2)            & Quadratic\\
    O(n^3)            & Cubic\\
    O(k^n)            & Exponential\\
    O(n!)             & Factorial\\
  \end{tabularx}
  \caption{A number of common complexities and their equivalent growth rates}
  \label{table:complexity}
\end{table}

The first parameter is the number of lines that the bracket should occupy, and the second parameter is the width of the text on the right of the bracket.

The result looks something like this: Screenshot of the table

2

Here is a solution with {NiceTabular} of nicematrix and its built-in command \SubMatrix in the \CodeAfter.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\begin{NiceTabular}{lll}
Aardvark & Armenia & \Block{2-1}{things beginning with vowels} \\
Elephant & Ethiopia \\
Platypus & Portugal & \Block{2-1}{things beginning with consonants} \\
Zebra  & Zimbabwe \\
\CodeAfter
  \SubMatrix{.}{1-1}{2-2}{\}}
  \SubMatrix{.}{3-1}{4-2}{\}}
\end{NiceTabular} 
\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Outuput of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .