9

I am using LaTeX for creating PDF files automatically from within Python scripts. The documents I create basically consist of just one big table, which can span several pages. It consists of three parboxed columns. Each item can contain a longer text. So far so good.

At this moment I am using longtable like so:

\begin{longtable}{@{}p{\inoutwidth}@{\hspace{\columnsepx}}p{.35\commentwidth}@{\hspace{\columnsepx}}p{.65\commentwidth}@{}}

Problem is, that even a single cell may contain so much text that it does not fit on one page. Which means I need a page break within an item, not only between items.

Well, ideally the table would only be broken between the rows. However, when one item exceeds the space available on a page, a page break would have to occur in the middle of the table row.

It's not trivial, because any or all of the table columns could contain a large portion of text inside one row. So a page break could impact on one or many columns.

The longtable I am using now put page breaks only between rows. If one row contains too much text, it just runs down the page and some text will be outside the page boundary thus invisible. Does not look nice.

Any ideas?

Cheers!

2
  • 2
    It sounds like tabular is not the right way to do this. If you have page breaks inside table cells, what is the table doing for you? Better to structure your data differently.
    – Seamus
    Jan 26, 2011 at 12:36
  • It seems not possible to break a page in one tabular line. However, I'm still interested in it, if there is any method using something other than tabular or longtable etc.
    – Leo Liu
    Jan 26, 2011 at 13:13

2 Answers 2

4

The ConTeXt source. The image shows the first two pages

\definepapersize[DE][width=11cm,height=15cm]
\setuppapersize [DE][DE]
\setuplayout[width=10cm,height=12cm]
%\setuptabulate[split=no]

\starttext
\starttabulate[|c|p(5cm)|]
\NC 1.\NC \input knuth\NC\NR\HL % a new tab line
\NC 2.\NC \input knuth\NC\NR\HL
\NC 3.\NC \input knuth\NC\NR\HL
\NC 4.\NC \input knuth\NC\NR\HL
\NC 5.\NC \input knuth\NC\NR\HL
\stoptabulate

\stoptext

enter image description here

2
  • That looks interesting. I played with it, and it works. However, I would like to have page breaks within a table row only if that row does not fit on one page. If e.g. my 2nd table row does not fit on page one, but it is not larger than a page itself, I would like the page break between row 1 and 2 (and not in the middle of row 2). So I'd like to keep the rows intact and on the same page, only except if the row is simply too big to go on one page. In that case it can start immediately after the first row and then page-break where (and as many times as) necessary.
    – svenor
    Jan 26, 2011 at 14:09
  • 1
    then you have to put the complete cell contents into a box and then measure its height and then decide for a pagebreak or not.
    – user2478
    Jan 26, 2011 at 14:12
3

A general solution is only possible with ConTeXt. With LaTeX you can only improve the situation.

  • You can set every column as a single document with a textwidth of the current columnwidth. At the end you can insert the longtable with pdfpages, it allows pages side by side. But this only works for two pages.
  • You can insert manual \newpage with a \parfillskip=0pt in the last line where you insert the page break, then this line will be stretched to the whole column width. The manual page break does not show in the output:

    \documentclass{article}
    \usepackage{longtable}
    \textwidth=6cm
    
    \begin{document}
    
    \begin{longtable}{p{3cm}p{2cm}}
    Some really nonsense text for the first column,
    where now is a problem with the page break
    &
    some more text \\
    foo & bar
    \end{longtable}
    
    \begin{longtable}{p{3cm}p{2cm}}
    Some really nonsense text for the first column,
    where \parfillskip=0pt & % for manual page break
    some more text \\
    \newpage
    now is a problem with the page break\\
    foo & bar
    \end{longtable}
    
    \end{document}
    
2
  • Can you give a hint of the solution in ConTeXt? Maybe in a different answer, so that we can upvote it separately. Jan 26, 2011 at 13:20
  • Well, I didn't want to do manual pagebreaks, as when I'm compiling the TeX sources I don't know where manual page breaks are necessary or not.
    – svenor
    Jan 26, 2011 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .