9

I am having troubles with \multicolumn. In the second row the cells containing a 9 should have equal sizes. How can I achieve this?

\documentclass{article}

\begin{document}
  \begin{center}
    \begin{tabular}{|c|cccccc|}
      \hline
      \textbf{faz} & \multicolumn{6}{c|}{18}\\
      \hline
      \textbf{bar} & \multicolumn{3}{c|}{9} & \multicolumn{3}{c|}{9}\\
      \hline
      \textbf{baz} & \multicolumn{2}{c|}{6} & \multicolumn{2}{c|}{6} &  \multicolumn{2}{c|}{6}\\
      \hline
    \end{tabular}
  \end{center}

\end{document} 

enter image description here

1 Answer 1

15

Yes, this behaviour is bizarre, but there is an explanation. Since you void the 6 column definition using \multicolumns in the second part of your column alignment specification, LaTeX has no idea what the alignment should be for that part of the table.

My suggestion would be to insert a dummy line with nothing in it that spans the entire width of the table, including every column entry. Then skip back (vertically) to typeset the remainder of your table. This will ensure LaTeX knows there's 6 columns that you want to split up in a 6/3-3/2-2-2 \multicolumn fashion.

Here is your minimal example with the correction:

enter image description here

\documentclass{article}

\begin{document}
  \begin{center}
    \begin{tabular}{|c|cccccc|}
      \hline
      \multicolumn{1}{c}{} & & & & & & \\[\dimexpr-\normalbaselineskip-\arrayrulewidth]% Correct for mis-alignment
      \textbf{faz} & \multicolumn{6}{c|}{18}\\
      \hline
      \textbf{bar} & \multicolumn{3}{c|}{9} & \multicolumn{3}{c|}{9}\\
      \hline
      \textbf{baz} & \multicolumn{2}{c|}{6} & \multicolumn{2}{c|}{6} &  \multicolumn{2}{c|}{6}\\
      \hline
    \end{tabular}
  \end{center}

\end{document}
1
  • Why did we add 7 columns in the \begin{tabular}{|c|cccccc|} statement? The maximum number of columns I see is 4 which is in the last row. Commented Aug 7, 2015 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .