How do I correctly multicolumn a tabularx while preserving the correct width?
When relatively short content is inserted into the \multicolumn
, it can be done with l
, c
, or r
. However, if the content does not fit into the width of the multi-column, one needs either X
or p
and the correct width must be computed. This question asks how to do this.
MWE
\documentclass{article}\usepackage{tabularx}\begin{document}\pagestyle{empty}\newcommand{\sbl}{\tiny Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.}\begin{tabularx}{0.95\textwidth}{X|X|X|X|X} \hline c\hfill 1 & c\hfill 2 & c\hfill 3 & c\hfill 4 & c\hfill 5\\\hline c\hfill 1 & c\hfill 2 & c\hfill 3 & c\hfill 4 & \sbl\\\hline c\hfill 1 & c\hfill 2 & c\hfill 3 & c\hfill 4 & \multicolumn{1}{X}{\sbl}\\\hline c\hfill 1 & c\hfill 2 & c\hfill 3 & \multicolumn{2}{X}{\sbl}\\\hline c\hfill 1 & c\hfill 2 & \multicolumn{3}{X}{\sbl}\\\hline c\hfill 1 & \multicolumn{4}{X}{\sbl}\\\hline \multicolumn{5}{X}{\sbl}\\\hline\end{tabularx}\end{document}
Using 2\hsize
does not do the trick as suggested many a place.
c\hfill 1 & c\hfill 2 & c\hfill 3 &\multicolumn{2}{>{\hsize=2\hsize}X}{\sbl}\\\hline % <--- does not work
What is the correct way to do this?