[Tex/LaTex] Longtable puts caption and/or header on the next page

captionslongtablepositioning

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

Here is a demonstration, bottom of a page:

enter image description here

Top of the next page:

enter image description here

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?

Best Answer

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}