Table with underscript

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


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

Tags:

Arrays