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 want to notate some information to table column groups, using underbraces. So there should be an \underbrace under the table, that stretches over multiple rows. I tried the following:

\begin{tabular}{r|c|c|c|c}
  i & 0 & 1 & 2 & 3 \\
  \multicolumn{1}{c}{} & \multicolumn{3}{c}{$\underbrace{\hfill}_{a_1}$} & \multicolumn{1}{c}{$\underbrace{\hfill}_{a_1}$}
\end{tabular}

The \hfill here doesn't work as I'd expect. The brace isn't stretched, but remains small and is centered. How can I make it stretch?

share|improve this question

migrated from stackoverflow.com Oct 18 '12 at 20:54

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers 2

up vote 4 down vote accepted

enter image description here

\documentclass{article}

\begin{document}

\begin{tabular}{r|c|c|c|c}
  i & 0 & 1 & 2 & 3 \\
  \multicolumn{1}{c}{} & \multicolumn{3}{c}{\upbracefill}& \multicolumn{1}{c}{\upbracefill}\\[-1ex]
  \multicolumn{1}{c}{} & \multicolumn{3}{c}{$\scriptstyle a_1$}& \multicolumn{1}{c}{$\scriptstyle a_2$}\\
\end{tabular}


\end{document}
share|improve this answer
add comment

Yes, you need to pad the contents that is spanned with the appropriate spaces:

enter image description here

\documentclass{article}
\begin{document}
\begin{tabular}{r|c|c|c|c}
  $i$ & 0 & 1 & 2 & 3 \\
  \multicolumn{1}{c}{} & 
    \multicolumn{3}{@{}c@{}}{$\underbrace{\hspace*{\dimexpr6\tabcolsep+2\arrayrulewidth}\hphantom{012}}_{a_1}$} & 
    \multicolumn{1}{@{}c@{}}{$\underbrace{\hspace*{2\tabcolsep}\hphantom{3}}_{a_2}$}
\end{tabular}

\bigskip

\begin{tabular}{r|c|c|c|c}
  $i$ & 0 & 1 & 2 & 3 \\[\dimexpr-\normalbaselineskip+1ex]
  \multicolumn{1}{c}{} & 
    \multicolumn{3}{@{}c@{}}{$\underbrace{\hspace*{\dimexpr6\tabcolsep+2\arrayrulewidth}\hphantom{012}}_{a_1}$} & 
    \multicolumn{1}{@{}c@{}}{$\underbrace{\hspace*{2\tabcolsep}\hphantom{3}}_{a_2}$}
\end{tabular}
\end{document}​

Using the column specification @{}c@{} removes any column padding for that (multi-)cell entry. The \underbrace is placed under a space of size 6\tabcolsep+2\arrayrulewidth and text of horizontal width equivalent to 012 (in the first \underbrace), which is the same amount of structured information in the tabular.

I've added a second alternative that adjusts the vertical alignment under the tabular, which I think is better.

If you're not sold on a tabular, the easier thing to do is of course:

enter image description here

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\newcommand{\sep}{\mathclap{|}}% Separator
\begin{document}
\[
  i \quad\sep\underbrace{\quad 0 \quad\sep\quad 1 \quad\sep\quad 2 \quad}_{a_1}
  \sep
  \underbrace{\quad 3\vphantom{|} \quad}_{a_2}\sep
\]
\end{document}​

mathtools provides \mathclap - a zero-width box in math mode that centres its contents.

share|improve this answer
add comment

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.