3

The answers on how to spread table columns evenly under a multicolumn seem to suggest that this is not possible, e.g. https://tex.stackexchange.com/a/60604/36836. It seems hard to believe that LaTeX has this restriction.

Here is an example showing the basic problem of spreading columns evenly:

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{tabular}{cccc}
\toprule
 & \multicolumn{3}{c}{some longer text here}\\
\cmidrule{2-4}
 & 1 & 2 & 3\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}

\end{document}

The last column, 3, take more space than the other columns.

enter image description here

1

You can try updating your source as follows. Change the position of column 3. Hope this helps.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{cccl}
\toprule
 & \multicolumn{3}{c}{some longer text here}\\
\cmidrule{2-4}
 & 1 & 2 & 3\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}

\end{document} 

Edit as per the comment. You can set the values in the tabular position environment as per your requirements. A sample have been shown below. Sorry for the late reply.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\renewcommand*{\arraystretch}{1}
\begin{tabular}{lp{1cm}p{1cm}p{1cm}}
\toprule
 & \multicolumn{3}{c}{some longer text here}\\
\cmidrule{2-4}
 & 1 & 2 & 3\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}
\end{document}
10
  • 1
    Thanks. That's better than the original but then there is still a large chunk of empty space. I'd prefer the distribution of space evenly.
    – Daniel
    Nov 11 '19 at 14:39
  • 1
    Great but not perfect because now one needs to set the column width manually, which is close to setting the table with manually.
    – Daniel
    Nov 11 '19 at 14:54
  • 1
    A small improvement of your code to get closer to the original's alignment is to add \usepackage{array} and use as column alignment l>{\centering}p{1cm}>{\centering}p{1cm}>{\centering}p{1cm}.
    – Daniel
    Nov 11 '19 at 14:55
  • 2
    Or even nicer l *{3}{>{\centering}p{1cm}}.
    – Daniel
    Nov 11 '19 at 15:12
  • 2
    @Daniel Yes, exactly. If the cell's content is short you can use the w type to avoid the need for centering (and correctives like arraybackslash).
    – TeXnician
    Nov 12 '19 at 9:13
2

It seems the problem was putting LaTeX commands in front of \toprule.

Note that you only have to use \makebox in one row to establish the widths.

\documentclass{article}
\usepackage{booktabs}
\newsavebox\tempbox
\begin{document}

\savebox{\tempbox}{some longer text here}% measure width
\begin{tabular}{cccc}
\toprule
\dimen0=\dimexpr \wd\tempbox/3 - 4\tabcolsep/3\relax
 & \multicolumn{3}{c}{\usebox\tempbox}\\
\cmidrule{2-4}
 & \makebox[\dimen0]{1} & \makebox[\dimen0]{2} & \makebox[\dimen0]{3}\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}

\end{document}

demo

4
  • replacing ` \divide\dimen0 by 3\\ ` works---but now how to insert text in the first row which remains blank
    – js bibra
    Nov 11 '19 at 14:38
  • Oops, must use global box. Weird! Nov 11 '19 at 14:45
  • I get the crash too. But don't know why.
    – Daniel
    Nov 11 '19 at 15:00
  • @daniel - The bug is going into an infinite loop rather than catching the problem. Using \hline instead of \toprule gives a improper \noalign error message. Nov 15 '19 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.