[texhax] equal width tabular columns when using a long multicolumn heading

Heiko Oberdiek heiko.oberdiek at googlemail.com
Fri Dec 2 09:27:35 CET 2011


On Thu, Dec 01, 2011 at 11:24:17PM -0800, jtzzaa11-texhax1 at yahoo.com wrote:

> I have a tabular with several columns preceded by a heading in a multicolumn. However, the heading is wider than the combined width of the columns, which results in the columns having different widths. Here is a minimal example:
> 
> \begin{tabular}{ c c c }
> \multicolumn{3}{c}{long heading}    \\    
> 1 & 2 & 3\\
> \end{tabular}
> 
> 
> which results in 
> 
> 
> long heading
> 1 2         3
> 
> 
> so the last column is much wider than the first two.
> Is there a way to automatically generate equal width columns whose combined width equals the width of the long heading?. I am trying to avoid manually fixing the width of the columns, for example, using p{2cm}.

\documentclass{article}
\usepackage{tabularx}
\usepackage{calc}
\begin{document}
\begin{tabularx}{\widthof{long heading\kern2\tabcolsep}}{XXX}
\multicolumn{3}{c}{long heading}\\% (no space before \\)
1 & 2 & 3\\
\end{tabularx}
\end{document}

Yours sincerely
  Heiko Oberdiek


More information about the texhax mailing list