# Table with underscript

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

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

Any idea?

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}

$\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]
\end{tabular}

\end{document}


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}


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