Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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