Let's assume that I have a table containing two l type columns that both contain rather short amounts of text. In one of the following rows I want to use a \multicolumn that merges both columns. I want it to automatically be as wide as both above mentioned columns together.
I can either achieve this using \multicolumn{2}{p{<width>}} and visually estimate the needed with. As can be seen from the following example, this is not very accurate:
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\begin{tabular}{|ll|}
Some text & some more text \\ \hline
\multicolumn{2}{|p{4.2cm}|}{\lipsum[4]}\\
\end{tabular}
\end{document}
To get a better result, I can use the \widthof command from the calc package in order to measure the widths of the widest entries in both columns and calculate the required width for the multicolumn based on that.
\documentclass{article}
\usepackage{lipsum}
\usepackage{calc}
\begin{document}
\begin{tabular}{|ll|}
Some text & some more text \\
text & a significantly longer line of text\\ \hline
\multicolumn{2}{|p{\widthof{Some text}+\widthof{a significantly longer line of text}+2\tabcolsep}|}{\lipsum[4]}\\
\end{tabular}
\end{document}
However, this requires to manually determine the widest entry and entering it twice in the table (once in the column and once in the \widthof command) which makes this approach somewhat error-prone and not too flexible.
Being aware of the tabularx package that is somehow able to automatically calculate the required width that is needed to make a table as wide as a specified length, I wonder if there is a more automated solution than the above described ones.




ptype column. As you can see, the text still does not line up perfectly: https://i.stack.imgur.com/btUeY.png – leandriis Jul 07 '19 at 15:00