I'm trying to use a tabular with \underbraces under some of the columns. I don't seem to have figured out the right dimensions of the column widths and/or the braces -- I naively thought that using \multicol might simplify the problem. I'd like the columns to center on the braces (or vice versa). Any suggestions gratefully received... (MacTeX 2017)
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{calc}
\usepackage{xparse}
\usepackage{array}
\newlength{\entrywd}
\newlength{\entrybracewd}
\setlength{\tabcolsep}{6pt}
\newenvironment{testtable}[2][\textwidth]{%
\setlength{\entrywd}{#1/#2-2\tabcolsep}
\setlength{\entrybracewd}{#1/#2-\tabcolsep}
\begingroup
\centering
\tabular{*{#2}{p{\entrywd}}}
}{%
\endtabular
\par
\endgroup
}
\newcommand{\mkbrace}[1]{%
\entryi[#1]{\raisebox{0.5\baselineskip}{$\underbrace{\hbox to #1\entrybracewd{\hfill}}$}}%
}
%% Used this because an optional argument of \newcommand does not work with \multicolumn:
%% https://tex.stackexchange.com/questions/257902/defining-multicolum-by-macro-with-optional-argument/257904#257904
%% https://tex.stackexchange.com/questions/17133/custom-macro-for-multicolumn-with-without-xparse
\NewExpandableDocumentCommand{\entry}{ O{1} m }{%
\multicolumn{#1}{>{\centering}p{#1\entrywd}}{#2}%
}
\NewExpandableDocumentCommand{\entryi}{ O{1} m }{%
\multicolumn{#1}{>{\centering}p{#1\entrybracewd}}{#2}%
}
\parindent0pt
\begin{document}
\begin{testtable}{7}
\entry[2]{one and some more of this sort}&\entry{bla bla bla and more}&\entry{this goes on and on and more}&\entry{bunch of really boring stuff}&\entry{I wish I could figure out}&\entry{so that I could move on with this nonsense}\\
\mkbrace{2}&\mkbrace{2}&\mkbrace{3}\\
\end{testtable}
\begin{testtable}{5}
\entry[2]{one and some more of this sort}&\entry{bla bla bla and more}&\entry{this goes on and on and more}&\entry{bunch of really boring stuff}\\
\mkbrace{2}&\mkbrace{2}&\mkbrace{1}\\
\end{testtable}
\begin{testtable}[0.5\textwidth]{4}
\entry[2]{one and some more of this sort}&\entry{bla bla bla and more}&\entry{this goes on and on and more}\\[-\baselineskip]
\mkbrace{2}&\mkbrace{2}\\
\end{testtable}
\end{document}



|might be useful. – Dec 28 '17 at 22:45