Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
check out the bigdelims package (part of multirow) - –  prettygully Apr 8 '11 at 2:59
1  
You could also adapt this code, although that's probably overkill... –  Seamus Apr 8 '11 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. –  Peter LeFanu Lumsdaine Apr 8 '11 at 16:05

4 Answers 4

up vote 12 down vote accepted

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}
share|improve this answer

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}

share|improve this answer
    
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. –  Peter LeFanu Lumsdaine Apr 8 '11 at 16:10
\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

share|improve this answer
    
Thankyou — unfortunately this breaks up the structure of the table itself, which I really don’t want to do. –  Peter LeFanu Lumsdaine Apr 8 '11 at 15:57

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.