# Longtable puts caption and/or header on the next page

How to prevent LaTeX to put the table caption on the next page?

Here is a demonstration, bottom of a page:

Top of the next page:

As you can see, "táblázat 8: Sorirányok összesítése" - that is the caption of the table - was placed on the top of the next page. If the longtable has a header, then sometimes the header is repeated on the next page with the caption. But there is no data, just the header and the caption. I suspect that this is typographically incorrect. Is this a bug? Or is it by design?

-
Bug???? It couldn't possibly be one of those in my code:-) Hard to say without seeing the code, if you could post it here or send it to me (google my name for email address) I'll have a look. –  David Carlisle Oct 26 '12 at 20:29
I have sent an email, as requested. –  nagylzs Oct 26 '12 at 20:42

If you put the caption in the main table body longtable just considers it a normal row of the table and so doesn't consider it wrong to have that row as the only thing on the last page.

It is better to put it into the head or foot section so \endlastfoot if you want it last. If necessary you can also put a line or two of the actual table data into the last foot if you want to ensure that some lines stay with the caption.

So

\begin{longtable}{@{}rr@{${},{}$}rr@{${},{}$}rrr@{}}
\bottomrule
\caption{Sűrűségmérő egyenesek - Vízszintes}
\endlastfoot
\toprule

...

\end{longtable}


Not

\begin{longtable}{@{}rr@{${},{}$}rr@{${},{}$}rrr@{}}
\toprule

...
\bottomrule
\caption{Sűrűségmérő egyenesek - Vízszintes}
\end{longtable}

-
I'm giving an up on this, but this did not solve the problem yet. Now the caption is written above a footnote at the end of the page. Adding \clearpage doesn't help either, because sometimes it breaks the page in the middle, ending up in a series of half-filled pages. –  nagylzs Oct 28 '12 at 18:15
I have your example file and I'll try to look, haven't had any time this weekend. –  David Carlisle Oct 28 '12 at 18:16
I mean, "over a footnote", not above. Sorry. Of course, it can wait. Your suggestion was still useful. –  nagylzs Oct 28 '12 at 18:23