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'm trying to make a multicolumn in a 7 columns tabular.

\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
\end{tabular}
\end{document}

The "yes" cell is not working, I have a small cell (1 column) and a large "empty" right after it. The last two empties are ok.

share|improve this question
    
Welcome to TeX.SE! It's very helpful for readers of postings if people post not only code snippets but compilable minimum working examples (MWEs) that illustrate the issue at hand. I've taken the liberty of adding two lines of code at the top and one line at the bottom of your code to convert it into an MWE. –  Mico Jun 16 '12 at 11:03
add comment

3 Answers 3

up vote 6 down vote accepted

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

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.

share|improve this answer
add comment

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.

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.