4

while intensively using the longtable environment, I ran into a situation where a the table is broken to the next page immediately after its endfoot line, without any real table row on the starting page. How to fix this?

MWE:

\documentclass[english,11pt,a4paper]{article}
\usepackage{longtable}[2004/02/01]

\begin{document}
\vspace*{188mm}

Here nearly at bottom of page, a longtable follows\ldots
\begin{longtable}{|l|p{58mm}|}
%
\hline
\endfirsthead
%
\hline\multicolumn{2}{|l|}{\textsl{\ldots continued from previous page}}
\endhead
%
\multicolumn{2}{|l|}{\textsl{will be continued on next page\ldots}}\\*
\hline
\endfoot
%
\hline
\endlastfoot
%
aa: & 4711\\
\hline%
aaa: & 2\\
\hline%
aaaa: & 4711-2\\
\end{longtable}

\end{document}

The problem is that I'm going to create many documents automatically and therefore may not see such layout problems.

If the initial vertical space is a bit less or more, the problem disappears...

Thanks in advance for help and ideas!

2
  • It can experimentally be found that the critical minimum length is \vspace*{187.212502mm} for this example, at least in my envrionment. I don't know why and what that tells...
    – tueftl
    Commented Sep 18, 2012 at 11:46
  • @DavidCarlisle: with \setlength{\LTpre}{0pt} the problem disappears in this MWE (the minimum length then is \vspace*{189.338523mm}), but that seems to be not always a workaround.
    – tueftl
    Commented Sep 27, 2012 at 11:53

1 Answer 1

2

As a workaround, \usepackage{needspace} may be added to declare the minimum space for, say, 2 table rows (one data row and the continuation message).

Just add \newdimen\LTpreNeededspace once and the following code before each \begin{longtable}:

\setlength{\LTpreNeededspace}{\baselineskip}\addtolength{\LTpreNeededspace}{\arrayrulewidth}
%\showthe\LTpreNeededspace
\multiply\LTpreNeededspace by 2 % Request 2 table lines, each including single '\hline', to fit on a page
%\showthe\LTpre
\addtolength{\LTpreNeededspace}{\dimexpr\LTpre - \glueshrink\LTpre\relax}\addtolength{\LTpreNeededspace}{\arrayrulewidth}   % Additionally, request the top '\hline' and the minimum value of '\LTpre'.
\addtolength{\LTpreNeededspace}{2.2pt}  % The reason for this necessary add-on is not yet clear.
\Needspace{\LTpreNeededspace}
3
  • \setlength{\LTpreNeededspace}{\dimexpr\LTpre - \glueshrink\LTpre\relax} should do (assuming that the shrink component is finite, of course).
    – egreg
    Commented Sep 18, 2012 at 10:56
  • Edit: added the \dimexpr term as suggested by egreg and removed last paragraph including this link. Thanks! All my trials with boxes didn't lead to this target (to compute 8.0pt from the default 12.0pt plus 4.0pt minus 4.0pt of LTpre)...
    – tueftl
    Commented Sep 18, 2012 at 11:16
  • Edit: added another 2.2pt to the requested length (2.13pt were identified as minimum); compare with the critical minimum \vspace* value posted as comment to the question.
    – tueftl
    Commented Sep 18, 2012 at 11:49

You must log in to answer this question.

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