Consider this example:
\documentclass{report}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1-4]
another paragraph
another paragraph
another paragraph
another paragraph
anoteher paragraph
another paragraph
another paragraph
%anoteher paragraph
%another paragraph
\begin{longtable}{lr}
\caption{long table}\\
A&B\\
c&D
\end{longtable}
\end{document}
When compiled, the caption of the long table is on one page, while the table itself on another page:
How do I avoid such an awkward situation?
Comment on answers
An additional problem is introduced when using \hline immediately after the caption:
\documentclass{report}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{needspace}
\begin{document}
\lipsum[1-4]
another paragraph
another paragraph
another paragraph
another paragraph
anoteher paragraph
another paragraph
another paragraph
%anoteher paragraph
%another paragraph
%\Needspace{5\baselineskip}
\begin{longtable}{lr}
\caption{some table}\\*
\hline
A&B\\
c&D\\
E&F
\end{longtable}
\end{document}
Even when using \\* we revert to the initial state of affairs:
It appears the problem can be solved by uncommenting the line %\Needspace{5\baselineskip}
However, it seems some manual adjustment is needed to \Needspace in the case of multiline captions.
Consider this example:
\documentclass{report}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{needspace}
\begin{document}
\lipsum[1-4]
another paragraph
another paragraph
another paragraph
another paragraph
anoteher paragraph
%another paragraph
%another paragraph
%anoteher paragraph
%another paragraph
\Needspace{5\baselineskip}
\begin{longtable}{lr}
\caption{\lipsum[1][1-3]}\\*
\hline
A&B\\
c&D\\
E&F
\end{longtable}
\end{document}
The result is again the same:
This case is fixed by changing 5 in \Needspace{5\baselineskip} to 6.




\\*instead of\\after the\caption? – Arash Esbati Mar 02 '19 at 13:01\\*: The same as\\but disallows a page break after the row." – moewe Mar 02 '19 at 13:28