So I am writing a programming book, and I use \section for each topic. For example, I'd write,
\section{Another way to double-space a file}
\begin{lstlisting}
awk 'BEGIN { ORS="\n\n" }; 1'
\end{lstlisting}
BEGIN is a special kind of pattern which ...
\section{Triple-space a file}
....
Sometimes I get a situation where the title of the section is at the very bottom of the page, and the example is at the beginning of a new page, etc.
Does anyone know how can I force \sections to be on a new page if all of it doesn't fit in the current page?
I am using memoir document class, btw.
\pagebreak? – Thorsten Apr 30 '11 at 08:30\penalityprimitive to control where page breaks are encouraged. The\sectiondefinition should use this to discourage page breaks right after it. You can try a\goodbreakbefore\sectionor\raggedbottomin the preamble. – Christian Lindig Apr 30 '11 at 08:48\sectiontries to avoid creating orphans, but apparently insertinglstlistingwithout any preceding text breaks this. – Andrey Vihrov Apr 30 '11 at 10:21\sectionandlstlistingis a paragraph break. IIRC, this breaks the\sectionorphan behaviour. – You Aug 08 '11 at 18:30