# Longtable continues into footer

I am using the longtable package to span tables across multiple pages. However sometimes (to me randomly, however so far only i quite complex documents) the longtable doesn't break like intended, but continues into the footer.

I tried to come up with a simple minimal example, but the tex files contained in Example1.7z file (link below) was the best i could do.

-

Could you really not make a more minimal example? longtable is a bit confused by the floating table. If you put \clearpage in front of that table it gets back in sync.

I do not have all the packages you referenced but could still see the effect if I ignored the missing package error (so clearly the example could be more minimal)

You also want to remove all \begin{center} around your longtables as they have no affect on centering and just produce anomalous vertical space. Also

\newcommand{\mytable}[4]{
\begin{table}[htp!]


not including t is an error (LaTeX warns of that when you run the file, and not including p makes it far more likely the table foes to the end of the document.

and you have a missing percent here

  \end{table}%
}

-
You are absolutely correct about your points. However they don't affect the actual problem. I considered the \clearpage solution as a last resort, as it look a bit weird to clear the page if the table is small. I will try to make a more minimal example and update the question. –  emher Nov 24 '12 at 14:55
Needing the manual \clearpage isn't ideal but it is what is needed (if longtable had correctly detected the earlier table it would have added the clearpage itself). the table isn't that small in particular it does not fit in the space at the bottom of the page so a page break before the table is exactly what you need (although it would be better if it was automatically added) –  David Carlisle Nov 24 '12 at 14:57
The tex code is generated in C# on runtime from data extracted from a DB. Hence i can't put in the \clearpage manually when needed, as the table could contain anything from 1 to 200 rows. Maybe i should have pointed that out earlier, but i didn't think it was relevant to the problem at hand. The example files have been updated, the example is a bit simpler now. –  emher Nov 24 '12 at 15:16