When I try to use multicolumn inside a tabularx
environment, I get this weird behaviour; where the column doesn't fill the whole width.
Anyone know why this is happening, and how I can fix it?
\documentclass[12pt]{article}
\usepackage{tabularx,lipsum}
\begin{document}
\begin{tabularx}{\textwidth}{|X|X|}
\hline
\multicolumn{2}{|X|}{\sffamily Lorem ipsum dolor sit amet,}\\\hline
\multicolumn{2}{|X|}{\lipsum[2]}\\\hline
\sffamily Lorem av:&\sffamily Ipsum:\\
foo&bar\\\hline
\end{tabularx}
\end{document}
Best Answer
You have to specify
\hsize
like|>{\hsize=2\hsize}X|
. If it is for three columns3\hsize
and so on. To be precise, take the\tabcolsep
and one\arrayrulewidth
in to account likeCode:
As an example, for three columns you have to use
as in
Here there are three columns, six
\tabcolsep
s and 4\arrayrulewidth
s. Of these 2 outer\tabcolsep
s and 2 outer\arrayrulewidth
s are retained (inside multi column) while the space for 4\tabcolsep
s and 2\arrayrulewidth
s have to be used.