I am reading user generated data and am trying to automate the layout. I would like the tables to stretch the width of the page, hence the use of tabularx
. Further there may be times when some tables need to be broken over two pages, hence I need longtable
. Then there was a problem for which this answer helped by leading me towards ltablex
. But once again there is a problem.
The MWE below demonstrates my problem.
Using just tabularx
everything looks nice, but switching to ltablex
causes the short table to be short in width as shown below.
Question: How can I have the best of both tabularx
and longtable
?
\documentclass{article}
% \usepackage{tabularx} % with this, everything is ok unless there is a table that stretches over two pages
\usepackage{ltablex} % with this, the first table doesn't stretch and is not left aligned
\begin{document}
\begin{tabularx}{\textwidth}{rrX}
\hline
col1 & col2 & col3 \\
\hline
3 & 6 & short comment\\
\hline
\end{tabularx}
\begin{tabularx}{\textwidth}{rrX}
\hline
col1 & col2 & col3 \\
\hline
3 & 6 & some long comment that should stretch to at least the edge of the page so that it wraps back to a second line. \\
\hline
\end{tabularx}
\end{document}
xltabular
environment.