1

I've created a table where multicolumn cells appear to not even be spanning the width of one of the two columns it was told to, and the adjacent multicolumn cell is spanning more than the two columns it was told to.

I find this to be entirely unexpected.

Here's an example:

\documentclass{article}

\usepackage{fontspec} \setmainfont[Scale=MatchUppercase]{Libertinus Serif}

\usepackage{multirow} \usepackage{booktabs}

\begin{document}

\begin{tabular}{|c|r|p{2em}|p{1em}|p{1em}|p{2em}|} \toprule \multicolumn{2}{|r|}{1:} & A & \multicolumn{2}{|c|}{B-C} & D \ \midrule \multirow{3}*{2-4} & 2: & a & \multicolumn{2}{|c|}{b-c} & d \ & 3: & \multicolumn{2}{|c|}{a-b} & \multicolumn{2}{|c|}{c-d} \ & 4: & \multicolumn{4}{|c|}{a-d} \ \midrule \multicolumn{2}{|r|}{5:} & \multicolumn{2}{|c|}{a-b} & \multicolumn{2}{|c|}{c-d} \ \bottomrule \end{tabular}

\end{document}

(Note that I don't usually use vertical dividers, but did in this example to keep track of the edges.)

Output of the above example:

Output of code above, with a-b in row 3 less than the width of column A, and c-d in row 3 spanning more than the width of columns B-C and D

In the output of the example, cell "a-b" in row 3 is told to span 2 columns, but it takes up less space than the single column it's in. Conversely, cell "c-d" is told to span two columns, but it spans more than three!

What I would expect is something more like the following, with changes in red showing what I would expect to be more like two-column-width spacing.

same image as above, but with cells in rows 3 and 5 repositioned so that two-column cells are centered and take up two columns

What am I doing wrong?

  • Taken together, your \multicolumn statements obliterate all usable information about the supposed fixed widths of the underlying columns for use in rows 3 and 5. – Mico Dec 11 '23 at 20:02
  • 1
    Consider adding a blank first row, which should set the lengths for all fixed-width columns, then killing it, like this: \begin{tabular}{...} & & & & & & & \\[-\normalbaselineskip] <rest of tabular> \end{tabular} – Werner Dec 11 '23 at 21:06
  • @Mico, interesting. Why does that data get obliterated? It seems like the interface provided by \multicolumn is a bit at odds with the mechanism of its operation. I feel that my misunderstanding of how \multicolumn works is because the interface is misleading. Does the first argument not mean "take up n columns", and the columns' positions and widths are already defined the the p{}s? – Jonathan W. Dec 12 '23 at 21:41
  • Your intuition sounds reasonable, but it's not correct. Take the following, deliberately contrived, example: \documentclass{article} \begin{document} \begin{tabular}{p{4in}} \multicolumn{1}{c}{u} \end{tabular} \end{document}. The tabular should be about 4" wide, right? Wrong! It's only as wide as the lowercase letter u (plus some whitespace padding, in the amount of \tabcolsep, on either side of u). That's why I wrote that \multicolumn can obliterate the underlying information. Do please study the examples contained in the link to the earlier question to (re)develop your intuition. – Mico Dec 12 '23 at 22:56

0 Answers0