TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a table to show how an object fills some space directions. Here is my code

\begin{tabular}{lcccccccccc}
& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
\hline 
D5 & x & x & x &  & x & x & x &  &  & 
\end{tabular}

and I get this

enter image description here

Now what I would like is to insert a bracket under columns 0-4 as in this image

enter image description here

Any idea?

share|improve this question
up vote 8 down vote accepted

You can use zref-savepos for computing the displacement.

The arguments start and end are arbitrary labels, which should be different for each application.

\documentclass{article}
\usepackage{amsmath}
\usepackage{zref-savepos}

\newcommand{\addunderbrace}[3]{%
  $\underbrace{\hspace{\numexpr\zposx{#2}-\zposx{#1}\relax sp}}_{\text{#3}}$%
}
\newcommand\vertbackup{%
  -\dimexpr\normalbaselineskip-\dp\strutbox\relax
}

\begin{document}

\begin{tabular}{lcccccccccc}
& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
\hline
D5 & \zsaveposx{start}x & x & x &  & x\zsaveposx{end} & x & x &  &  & \\[\vertbackup]
& \multicolumn{5}{c}{\addunderbrace{start}{end}{A A A}}
\end{tabular}

\end{document}

enter image description here

share|improve this answer

Here, I just made the underbrace part of a new row. I stacked the label under the underbrace, and the underbrace width, \dimexpr5ex+9\tabcolsep, was selected based on content of the underbraced lines. the 1ex width of the \makebox is based on the width of the column data containing the 0 header.

\documentclass{article}
\usepackage{stackengine}
\stackMath
\begin{document}
\begin{tabular}{lcccccccccc}
& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
\hline 
D5 & x & x & x &  & x & x & x &  &  & \\[-8pt]
   &\makebox[1ex][l]{%
      \stackunder{\underbrace{\hspace{\dimexpr5ex+9\tabcolsep\relax}}}{T \times T}}
\end{tabular}
\end{document}

enter image description here

share|improve this answer
    
I vote all posts to everyone I know and who have helped me. – Sebastiano 9 hours ago

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.