Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
3  
install the package ltablex (mirror.ctan.org/macros/latex/contrib/ltablex). It allows a pagebreak for tabularx –  Herbert Jun 21 '12 at 21:43
    
@Herbert: I stored the sty-file in /usr/local/texlive/2010/texmf/tex/ltablex but. However I get the message "'ltablex.sty' no found." –  John Jun 21 '12 at 23:09
    
did you run texhash? However, the file should go into .../texlive/texmf-local/tex/latex/ltablex/ –  Herbert Jun 22 '12 at 5:16
    
@Herbert: Many thanks. I moved everything to the other folder and run texhash. When adding \usepackage{ltablex} to the preamble and using \begin{tabularx}{\textwidth}{p{2cm}X} instead of \begin{foo} it just works fin. But why isn't possible to use my foo-environment as defined? –  John Jun 22 '12 at 6:02
    
that always depends on how an existing environment is defined. In thisa case it is the endtabularx which cannot be used inside another definition. –  Herbert Jun 22 '12 at 6:05

2 Answers 2

up vote 7 down vote accepted

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

share|improve this answer
    
I used description beforehand but the disadvantage is that the description-environment does not align the text of each item to each other, as for instance the tabular- or tabularx-environment do. –  John Jun 18 '12 at 21:43
    
description is just one example list the underlying latex list construct is very flexible and can easily align the labels on the same line or just use enumerate and \item[label 1] but that has different horizontal spacing, but you might like it:-) either way it is vastly easier to customise a list than to break a TeX table mid-row. –  David Carlisle Jun 18 '12 at 22:08
    
I think description is just perfect, as I have non-enumerated items (see edit). Within my paper I have code-snippets. Following the code-snippet I would like to explain some of the commands of the code in a glossary-like environment, such as description. I just don't see how to customise the description-environment, so that it appears like my tabularx-approach. –  John Jun 21 '12 at 21:28
1  
code and pic added for list (basically a merger of description and thebibliography from the standard classes) –  David Carlisle Jun 21 '12 at 21:39
    
How can I set a fix length, instead of \settowidth\labelwidth{{#1}}? I know I could write \begin{my list}{This is the labelwidth which I would like to use throughout my whole document}, but maybe you have a better solution? –  John Jun 21 '12 at 23:07

You should have a look at the tabu package which provide the longtabu environment which should do what you are after (split tables across multiple pages).

However as David points out, it will not split cells across pages.

Alternatively, another solution would be to use the parallel package :

\documentclass[a4paper,12pt]{article}

\usepackage {lipsum}
\usepackage {calc}
\usepackage {parallel}

\begin{document}

\begin{Parallel}{2cm}{\textwidth-3cm}
   \ParallelLText{test 1}
   \ParallelRText{\lipsum[1-4]}
   \ParallelPar
   \ParallelLText{test 2}
   \ParallelRText{\lipsum[1-4]}
   \ParallelPar
   \ParallelLText{test 2}
   \ParallelRText{\lipsum[1-4]}
\end{Parallel}

\end{document}

enter image description here

share|improve this answer
    
Could you please post your tabu-approach using my example. I implemented \usepackage{array, xcolor, colortbl, longtable} in my preamble and added \begin{tabu}{p{2cm}X} Test1 & \LongText \Test2 & \LongText \LongText \end{tabu} to my example but it did not work. –  John Jun 18 '12 at 20:40
    
I get the "File 'tabu.sty' not found"-message, when implementing \usepackage{tabu} into my preamble. The problem is: I don't know how to install packages. I run TeXShop Version 2.47 on Mac OS 10.7.4. –  John Jun 18 '12 at 20:51
    
The message you are getting means that the package is not present in your installation of your TeX distribution. However TeXShop is just an editor so it doesn't give much details about your enviroment. If you are using TeXlive, then tlmgr install tabu should do the tick. I do not know the procedure with MacTeX. –  ArTourter Jun 18 '12 at 21:04
    
Is it possible that \usepackage{calc} is missing in your preamble? –  John Jun 18 '12 at 21:51
    
Quite possibly, I used lualatex to compile my example and it loads it automatically. I have modified my post. –  ArTourter Jun 18 '12 at 21:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.