Multicolumn 3 out of 6 doesn't work

When you have columns that are spanned in every row the underlying \halign primitive essentially removes the column from the calculation:

enter image description here

\documentclass{article}

\begin{document}

\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
& \multicolumn{6}{c|}{Parameters}\\
\hline
We don't care * & \multicolumn{2}{l|}{cause it's a test} & \multicolumn{2}{l|}{cause it's a test} & \multicolumn{2}{l|}{cause it's a test}\\
\hline
Punctuation ? & \multicolumn{3}{c|}{yes+} & empty & empty & empty \\ %& \multicolumn{3}{c|}{no}\\
\hline
 1&2&3&4&5&6&7
\end{tabular}


\end{document}

The problem comes from the fact that at not point in your table all the columns are used independently for the compiler to calculate their with. This is why, with @david-carlisle's answer, as soon as he adds a line with all the cells independently used, the layout changes.

If you want more control over your table you can use an environment which lets you set the width of them such as tabu or tabularx. but even there, without help, the environment will not know what to do.

\documentclass[a4paper,12pt]{standalone}
\usepackage{tabu}
\begin{document}
\begin{tabu}{|l|X|X|X|X|X|X|}
\hline
& \multicolumn{6}{c|}{Parameters}\\
\hline
We don't care * & \multicolumn{2}{l|}{cause it's a test} & \multicolumn{2}{l|}{cause it's a test} & \multicolumn{2}{l|}{cause it's a test}\\
\hline
Punctuation ? & \multicolumn{3}{c|}{yes+} & empty & empty & empty \\ %& \multicolumn{3}{c|}{no}\\
\hline
\end{tabu}

\end{document}

will give you

enter image description here

The tabu package gives you the \tabuphantomline so that cell widths can be calculated properly without printing anything:

\documentclass[a4paper,12pt]{standalone}
\usepackage{tabu}
\begin{document}
\begin{tabu}{|l|X|X|X|X|X|X|}
\hline
\tabuphantomline
& \multicolumn{6}{c|}{Parameters}\\
\hline
We don't care * & \multicolumn{2}{l|}{cause it's a test} & \multicolumn{2}{l|}{cause it's a test} & \multicolumn{2}{l|}{cause it's a test}\\
\hline
Punctuation ? & \multicolumn{3}{c|}{yes+} & empty & empty & empty \\ %& \multicolumn{3}{c|}{no}\\
\hline
\end{tabu}

\end{document}

which then gives you something probably more akin to what you were expecting:

enter image description here

tabu and tabularx add the X column type for which the column width is calculated so that all X cells have the same dimension (although multiplier are also possible). So for you example, having the last 6 columns as X column would probably make sense.


The reason the tabular example is throwing an error is that its basic setup is overspecified: It's set to have 7 columns overall, but the two lines only contain 4 and 5 columns, respectively. Digging deeper, one quickly finds that whereas the first column and the last two columns are identified uniquely by the setup you provide, columns 2 through 5 are not. There are too many degrees of freedom at the moment; what you're discovering is that LaTeX is unable to come up with the correct "guess" as to how you would like the columns to be grouped into multicolumns.

This may be verified by adding a "trivial" row such as

a & b & c & d & e & f & g\\

to your example.

Addendum -- After I posted this answer I noticed that David Carlisle already provided an answer. It contains much more precise information as to how LaTeX deals with what I call the excess degrees of freedom problem that makes the basic setup under-identified.

Tags:

Tables