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 \section
s to be on a new page if all of it doesn't fit in the current page?
I am using memoir
document class, btw.
Best Answer
My suggestion is to focus on getting the content and structure of your document in place before attending to details such as this. The reason is that the layout of your document will shift constantly while content is still being added. Because of this, the most efficient use of time is to focus on writing and ignore these details until the rough draft is done.
Once the rough draft is ready, then you can clean these bad section breaks up by inserting
\goodbreak
,\newpage
, etc. as part of the editing process.