2

When multicolumn headers in tables use more horizontal space than the columns they are 'heading', then the additional width is entirely allocated to the rightmost column. The following MWE:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{lccc}\toprule
  & \multicolumn{3}{c}{Wide multicolumn cell}\\
  & x & y & z  \\ \midrule
A & 1 & 2 & 3  \\  \bottomrule
\end{tabular}
\end{document}

Produces:

enter image description here

I would like to allocate the same amount of horizontal space to column x,y, and z. I do realize that an easy fix would be to use fixed width columns for x, y, and z, but I am looking for a dynamic solution. So my questions are the following:

1) Is there an easy way to allocate the horizontal space equally to columns x,y, and z?

2) Assuming that the answer to 1) is no: What would be an elegant way to increase the width of a single variable-width column by a percentage, e.g., increase the width of column x to 150% of the default?

  • If you are happy to specify the overall width of the table, you could use tabularx and {lXXX} which would ensure the columns are equal width. Or you could calculate the width of the header text and then divide it into 3 and create the columns that way. But you need to know something at the point the column specification is given, I think. – cfr Jan 12 '16 at 23:21
3

A few possibilities:

enter image description here

\documentclass{article}
\usepackage{booktabs,tabularx}
\begin{document}
\setlength\parskip{1cm}

\begin{tabular}{lccc}\toprule
  & \multicolumn{3}{c}{Wide multicolumn cell}\\
  & x & y & z  \\ \midrule
A & 1 & 2 & 3  \\  \bottomrule
\end{tabular}

\dotfill


\begin{tabular*}{.5\textwidth}
                {l!{\extracolsep{\textwidth minus \textwidth}}lccc}
\toprule
  & \multicolumn{3}{c}{Wide multicolumn cell}\\
  & x & y & z  \\ \midrule
A & 1 & 2 & 3  \\  \bottomrule
\end{tabular*}

\begin{tabular}{lc@{\hspace{4em}}c@{\hspace{4em}}c}\toprule
  & \multicolumn{3}{c}{Wide multicolumn cell}\\
  & x & y & z  \\ \midrule
A & 1 & 2 & 3  \\  \bottomrule
\end{tabular}

\begin{tabularx}{.5\textwidth}{l*{3}{>{\centering\arraybackslash}X}}\toprule
  & \multicolumn{3}{c}{Wide multicolumn cell}\\
  & x & y & z  \\ \midrule
A & 1 & 2 & 3  \\  \bottomrule
\end{tabularx}

\begin{tabular}{lccc}\toprule
  & &\makebox[60pt]{Wide multicolumn cell}&\\
  & x & y & z  \\ \midrule
A & 1 & 2 & 3  \\  \bottomrule
\end{tabular}


\end{document}
| improve this answer | |
0

Thank you for these suggestions. Prefering to stick to the tabular environment, I was attracted to the second suggestion with the @{\hspace{4em}}, but to expand the width of a column on both ends would require adding half of the space to the left and right of the column. The result was that the multicolumn cell did also include the additional space, which is not desired. In addition it does not seem to work well with underlining the multicolumn cell (\cline{2-4}).

For the moment I prefer the following solution (even if it is probably an ugly hack...):

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\newcommand{\cspace}{\hspace*{2.5em}}
\begin{tabular}{lccc}
&  \cspace & \cspace & \cspace \\ [-2.5ex]
\toprule
  & \multicolumn{3}{c}{Wide multicolumn cell}\\ \cline{2-4}
  & x & y & z  \\ \midrule
A & 1 & 2 & 3  \\  \bottomrule
\end{tabular}
\end{document}

Result:

enter image description here

| improve this answer | |

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.