# [Tex/LaTex] Why does \extracolsep{\fill} not fill

horizontal alignmentspacingtables

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}


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.