[Tex/LaTex] Implementing page break in tabularx environment

longtablepage-breakingtabularx

Please consider the following example for better understanding. I would like LaTex to use page breaks within the tabularx environment, so that one part of the contains of \LongText will be displayed on the first and the rest on the second page. Maybe there is another useful package for page breaks within long tables or a complete other package for my purpose: a glossary within the main text.

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tabularx}

\usepackage{lipsum}

\begin{document}

\newenvironment{foo}{\tabularx{\textwidth}{p{2cm}X}}{\endtabularx}

\newcommand{\LongText}{This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.}

\lipsum[1-3]

\begin{foo}
Whatever & \LongText \\
Something else & \LongText \LongText
\end{foo}

\end{document}

Best Answer

The most direct package combining longtable and tabularx (by the same author as those two) is ltxtable. However neither it nor tabu will do what you want here, which is, I think, split within the row of the table. That is rather hard to achieve in TeX and can only really be done in very restricted circumstances. (Consider a general table with many columns, some of which may have images or nested tables), finding a place to break every column at the same place is very hard in general.

If your real example is as shown, a two column table with one line entries in the first column, do not use a table layout, use a list LaTeX lists can easily achieve that layout and naturally allow page breaks within items.

\documentclass{article}
\usepackage[ngerman]{babel}


\usepackage{lipsum}

\begin{document}

\newenvironment{foo}{\tabularx{\textwidth}{p{2cm}X}}{\endtabularx}

\newcommand{\LongText}{This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.}

\lipsum[1-3]
\newenvironment{mylist}[1]% #1 is widest label
     { \list{}%
           {\settowidth\labelwidth{{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep}%
}{\endlist}



\begin{mylist}{Something else}
\item[Whatever]  \LongText 
\item[Something else] \LongText \LongText
\end{mylist}

\end{document}

enter image description here

Related Question