[Tex/LaTex] Faulty page-break in longtable: starts with endfoot

longtablepage-breaking

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!

Best Answer

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}
Related Question