When the remaining rows of a longtable fit exactly onto the current page, longtable will instead create a widow by printing a footer on the current page and moving the last row onto the next page (with repeated header and footer).
This can be prevented by printing the last row as part of the last footer, but I am wondering why this is happening in the first place, and whether this could perhaps be fixed in the longtable package. (Conceptually, I would expect the algorithm to only start a new page after it has determined that the remaining contents do not fit onto the current page.)
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\begin{longtable}{l}
\caption{Caption}\
\toprule
Column heading\
\midrule
\endfirsthead
\caption[]{Caption} \
\toprule
Column heading\
\midrule
\endhead
\midrule
Continued on next page\
\midrule
\endfoot
\bottomrule
\endlastfoot
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
x\
\end{longtable}
\end{document}

longtable-- I will assume that you have more important things to do than typesetting tables with rows and rows consisting of the single letter "x" :-) -- you may decide to either forbid a linebreak in the penultimate row by changing\\to\\*or to provide a strategically placed\enlargethispage{1\baselineskip}instruction. – Mico Aug 31 '23 at 16:21\enlargethispage{1\baselineskip}such that it affects the right page, if your longtable runs across many pages (i.e. the general case). – oulenz Aug 31 '23 at 16:28longtableto contain at least two rows, in addition to whatever is produced by\endhead, instead of just one row. – Mico Aug 31 '23 at 16:51\end{longtable}has even been read from the file system. longtable can't look ahead and it can't go back and change decisions (but it could typeset 1000 row tables in 1990 on a machine with less than 1Mb of memory.... – David Carlisle Sep 03 '23 at 12:39