# Faulty page-break in longtable: starts with endfoot

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
%
\hline\multicolumn{2}{|l|}{\textsl{\ldots continued from previous page}}
%
\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!

-
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 Sep 18 '12 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 Sep 27 '12 at 11:53

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}

-
\setlength{\LTpreNeededspace}{\dimexpr\LTpre - \glueshrink\LTpre\relax} should do (assuming that the shrink component is finite, of course). –  egreg Sep 18 '12 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 Sep 18 '12 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 Sep 18 '12 at 11:49