8

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?

8

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

5

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

  • I vote all posts to everyone I know and who have helped me. – Sebastiano Jan 9 '17 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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