Table column widths disproportionate due to multicolumn cell being too long
It's a feature of the \halign
primitive:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\centering
\parskip2\baselineskip
\begin{tabular}{*5{c}}
\multicolumn{5}{c}{This is a piece of text. The longer it is, the longer the last column.} \\
1 & 2 & 3 & 4 & 5 \\
\hline
\end{tabular}
\begin{tabular}{*5{c}}
\multicolumn{5}{c}{\makebox[0pt]{This is a piece of text. The longer it is, the longer the last column.}} \\
1 & 2 & 3 & 4 & 5 \\
\hline
\end{tabular}
\begin{tabular*}{\textwidth}{@{\extracolsep{\textwidth minus\textwidth}}*5{c}@{}}
\multicolumn{5}{c}{This is a piece of text. The longer it is, the longer the last column.} \\
1 & 2 & 3 & 4 & 5 \\
\hline
\end{tabular*}
\begin{tabularx}{\textwidth}{*{5}{>{\centering\arraybackslash}X}}
\multicolumn{5}{c}{This is a piece of text. The longer it is, the longer the last column.} \\
1 & 2 & 3 & 4 & 5 \\
\hline
\end{tabularx}
\end{document}
Thank you so much David, this answer has helped me so much in using Excel2Latex. I now use this in my preamble
\usepackage{tabularx}
\usepackage{array}
\newcommand{\deftab}[2]{\begin{tabularx}{#1}{*{#2}{|>{\centering\arraybackslash}X}|}
and then use
\deftab{width}{no. of columns}
in place of the
\begin{tabular}
that Excel2Latex uses, and then I replace the necessary \end{tabularx}
at the end of the table. It automatically fixes all of these types of problems in tables of any size and does so without disrupting any formatting.