0

I have a simple example of the use of tabularx as follows.

\documentclass{article}
\usepackage{tabularx,lipsum}
\begin{document}
\lipsum[1-2]
\begin{tabularx}{\linewidth}{lX}
  2001 & \lipsum[1]\\
  2003 &  \lipsum[2]\\
    2003 &  \lipsum[3]\\
  2004 &  \lipsum[4]\\
\end{tabularx}
\end{document}

However, I would like the table to flow over two pages, while also wrapping the text. I looked at some of the examples in the longtable and longtabu packages but was not able to resolve this. Is there an easy way to make the table flow using tabularx. Thanks in advance!

  • 1
    abularx will not spli, look at xltabular (a question with an example was posted here a few minutes ago) that is a merge of tabularx and longtable – David Carlisle Mar 24 '22 at 20:52
  • 1
    notte however that table only break pages at \\ almost all tables using lX are better set as a list, then page breaking can happen naurally within the lipsum text, \item[2001] \lipsum \iem[2003]\lipsum.... – David Carlisle Mar 24 '22 at 20:59
  • Thank you! I see that xltabular will replace tabularx verbatim and do what I want. – user3236841 Mar 24 '22 at 21:01

3 Answers3

2

You miss the more valuable second comment. Consider check the solutions under the \usepackage[showframe]{geometry} test to realize the problem. The xltabular package is not the good solution in this case, because big and unbreakable table cells will usually produce awful gaps at the bottom of the page.

For this content, you can use better desclist, eqlist or enumitem list, or without any list package, a simple macro could be enough:

\documentclass{article}
\usepackage{parskip,lipsum}
\newcommand\xyz[1]{\par\hangindent5em\makebox[5em][l]{#1}\ignorespaces}
\begin{document}
\lipsum[1-2]
\xyz{2001} \lipsum[1] 
\xyz{2002} \lipsum[2] 
\xyz{2003} \lipsum[3] 
\xyz{2004} \lipsum[4] 
\lipsum[1-2]
\end{document}
Fran
  • 80,769
2

At long tables people usually add column headers on the top each table part as well repeat caption and ad information about table continuations. This enable each package supporting long table, however using tabularray package, adding this is very simple (and with short code):

\documentclass{article}
\usepackage{microtype}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\usepackage{lipsum}

\begin{document} \lipsum[1-2] \begin{longtblr}[ caption = {My long table}, label = {tab:longtblr?} ]{colspec = {lX[j]}, rowhead = {1}, row{1} = {font=\bfseries, c} } \toprule Year & Description \ \midrule 2001 & \lipsum[1] \ 2003 & \lipsum[2] \ 2003 & \lipsum[3] \ 2004 & \lipsum[4] \ \bottomrule \end{longtblr} \lipsum[1] \end{document}

enter image description here

Addendum Using `long table you should be aware that long table can only be broken between pages only between rows. This can cause that below table parts will be empty space (as is visible at above MWE).

In your case, when your table more remain to a list than table, that may be better to use solution provided by @Fran (+1) or simple use enumitem package:

\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}

\begin{document} \lipsum[1-2] \begin{itemize}[labelindent=0em,leftmargin=!] \item[2001] \lipsum[1] \item[2002] \lipsum[2] \item[2003] \lipsum[3] \item[2004] \lipsum[4] \end{itemize} \lipsum[1-2] \end{document}

In such cases looks of your document will be nicer:

enter image description here

Zarko
  • 296,517
0

Per the hint given by @DavidCarlisle, the question is addressed very well by simply replacing tabularx with xltabular and the entire syntax goes through without any changes. I like this solution given that it is simple and straightforward and wish I had known about xltabular a lot sooner!

\documentclass{article}
\usepackage{xltabular,lipsum}

\begin{document} \lipsum[1-2] \begin{xltabular}{\linewidth}{lX} 2001 & \lipsum[1]\ 2003 & \lipsum[2]\ 2003 & \lipsum[3]\ 2004 & \lipsum[4]\ \end{xltabular} \lipsum[1-2]

\end{document}

Zarko
  • 296,517