[Tex/LaTex] Controlling longtable page breaks

longtablepage-breaking

Is it possible to specify where the preferred page breaks in a longtable are? I'm trying to create a longtable with three types of rows:

  1. rows which should never be followed by a page break
  2. rows which can be followed by a page break if necessary
  3. rows which mark the preferred page break locations

I know that \\* will get me rows of type 1, but I don't know how to accomplish the other two.

Also, while there will generally be a row of type 2 or 3 every two or three rows, I'd still like to avoid big blocks of white space at the bottom of the page by introducing some stretchable spaces after each row:

  1. 0pt plus 1pt
  2. 0pt plus 1pt
  3. 12pt plus 6pt

I know I can use \\[12pt] to introduce a fixed amount of distance after a particular row, but changing this up for a stretchable space raises errors.

I've been able to do something like this in a list environment before by redefining \item, \par, and \\, but now need the header and footer capabilities of longtable. Is it possible to define some variants on \\ or \tabularnewline inside the longtable environment which will accomplish both these goals?

MWE (doesn't actually do much, but it gives you something to play with):

\documentclass[12pt,a5paper]{article}

\usepackage{longtable}

\newcounter{bla}
\newcommand\bla{\stepcounter{bla}row\thebla}

\setlength{\baselineskip}{12pt plus 1pt}

\begin{document}

\begin{longtable}{c}
\bla \\* \bla type 2 \\ \bla \\* \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\bla \\* \bla type 2 \\ \bla \\* \bla type 3\\[12pt]
\end{longtable}

\end{document}

Best Answer

Let' see.

  1. rows which should never be followed by a page break
  2. rows which can be followed by a page break if necessary
  3. rows which mark the preferred page break locations

Number 1 can be done with \\* as you have noticed. However, there is a bug that causes this not to work if it is followed by a \cline. There is a patch for this (see longtable multirow problem with cline and nopagebreak).

Number 2 is the normal row ending \\.

Number 3 can be done by adding \noalign{\penalty-5000} after the \\. The 5000 can be changed to get more or less preference for a page break. This will only work if there is enough stretchability in the page.

You can add stretchable space between rows with \noalign{\vskip 12pt plus 6pt}, but then the vertical lines will be broken.