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?

2 Answers 2

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

1
  • I vote all posts to everyone I know and who have helped me.
    – Sebastiano
    Commented Jan 9, 2017 at 20:45

You must log in to answer this question.

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