[Tex/LaTex] How to prevent page break between section heading and longtabu table

longtablepage-breaking

I have created a minimal working example (MWE) consisting of a section and a longtabu table.

\documentclass{report}

\usepackage{longtable,tabu}

\begin{document}
An initial line of text

\vskip 47.5em % Offset the section to close to the bottom of the page

\section{Test section}

\begin{longtabu}{l X}
    \textbf{Column 1} & \textbf{Column 2} \\
    \hline
    \\
    \endhead
    Cell 1 & Cell 2 \\
\end{longtabu}

Additional content

\end{document}

In the compiled document, which becomes two pages long, the section heading ends up at the end of the first page while the table (longtabu) ends up at the other. Why doesn't LaTeX prevent that a page break is inserted directly after the section heading, and how can it be fixed? If LaTeX has to break the page before the table has been finished, I want the page break to be inserted before the section heading.

Ideally, I want to obtain the same result as if a clearpage had been inserted right before the section heading started, if there would otherwise have been a page break between the section heading and the table.

Best Answer

Have a look at the needspace package. The functionality also exists in for example memoir. With it you can add something like: \needspace{5\baselineskip} before the headline. If not the given space is left on the page a page break will be inserted and in your case the header will end up on the next page.