# Avoid short sections at the end of page

I am using LyX and try to avoid the occurence of short text sections at the end of a page which start with a chapter/section etc. Is it possible to add a preamble line which can tell LyX that if a section only has less than e.g. 3 lines in the bottom of a page, it should be moved to the next page?

The way I solve this at the moment is to wait until my report is finished and then add \newpage where this occurs, but it's starting to bug me since I have quite large reports and feel that I loose a bit of control over the documents structure.

Here's an example: MWE

-
Anything that needs to be zipped up does not qualify as a MWE: meta.tex.stackexchange.com/questions/228/… –  StrongBad Oct 10 '12 at 10:08
sorry, I didn't know that. Edited to just be the .lyx file. Thank you for the heads up –  chwi Oct 10 '12 at 10:54

Assuming you mean lines and not sentences, you should be able to do this with the needspace package. The concept is as follows

\documentclass{article}
\usepackage{lipsum}
\usepackage{needspace}

\begin{document}
\section{First section}
\lipsum[1-4]

\needspace{6\baselineskip}
\section{Second section}
\lipsum[1-4]
An extra line

A second extra line

\needspace{6\baselineskip}
\section{Third section}
\lipsum[1-6]

\end{document}


In this case if there is not 6 baselineskips worth of space, the section gets moved to a new page (I chose 6 so I did not have to fiddle with the spacing to get things to move). It is not a perfect solution since I needed to add two lines to get the section to jump and not a single line.

You should be able to modify \section (and maybe \subsection etc) to include \needspace.

-