8

When using \extracolsep{\fill} to stretch out a sparse table to the full text width, inserting multicolumns whose text is “too long” breaks the filling.

Naïvely I would have expected the second row in both tables in the example below to look the same.

Why does that happen and what can I do about it?

\documentclass{article}
\setlength{\parindent}{0pt}
\begin{document}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|c|c|}
    \hline
    \multicolumn{2}{|c|}{Some text} \\
    \hline
    Left & Right \\
    \hline
\end{tabular*}

\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|c|c|}
    \hline
    \multicolumn{2}{|c|}{Some longer text with spaces} \\
    \hline
    Left & Right \\
    \hline
\end{tabular*}
\end{document}

enter image description here

1

1 Answer 1

5

Basically the table is first set as if for a tabular, so the long spanning entry forces the second column to be wider (so Right no longer fills the full width of that column and does not reach its right hand edge as it is a c column.) then after that alignment is done, because the natural width of the table is less than \linewidth, \extracolsep (that is \tabskip glue) is used to separate the columns but the column widths are already fixed.

You could use

\multicolumn{2}{|c|}{\makebox[0pt]{Some longer text with spaces}}

to hide the width, so long as you know it will fit within the specified width and won't overshoot the page.

4
  • Do you reckon this is a bug? (either code or documentation) This is certainly unexpected behaviour. Mar 17, 2020 at 3:09
  • it is the low level behaviour of halign so hard to avoid I think we mention it on the latex companion at least t also other answers on this site @henr Mar 17, 2020 at 6:56
  • @HenriMenke see also tex.stackexchange.com/search?q=user%3A1090+%5Cextracolsep+minus for an alternative setting of extracolsep that avoids this problem Mar 17, 2020 at 7:52
  • I think the trick David refers to above is of the type @{\extracolsep{\textwidth minus \textwidth}}: it worked for me in a situation just like the one described here.
    – PatrickT
    Apr 20 at 8:58

You must log in to answer this question.

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