latextextext-formatting

LaTeX - Lots of sections (with no content) running of the edge of the page?


I have a LaTeX document like this:

\documentclass{article}
\begin{document}

\section{1}
\section{2}
\section{3}
\section{4}
\section{5}
\section{6}
\section{7}
\section{8}
\section{9}
\section{10}
\section{11}
\section{12}
\section{13}
\section{14}
\section{15}
\section{16}
\section{17}
\section{18}
\section{19}
\section{20}
\section{21}
\section{22}
\section{23}
\section{24}
\section{25}
\section{26}
\section{27}
\section{28}
\section{29}
\section{30}

\end{document}

Lots of section headings, but no text in

It produces something like this:

As you can see it keeps all the section headings on one page, and won't break it into 2 pages. Everything above 26 has disappeared off the end of the page.

Is there anyway to get LaTeX to split these sections across multiple pages? I can't easily change the actual content of body, since it's autogenerated. I can change the preamble though. Is there anyway to do this by changing the preamble?


Solution

  • Adding \mbox{} after a section heading would allow the page break. You could introduce it globally in the preamble by:

    \makeatletter
    \g@addto@macro\@afterheading{\mbox{}}
    \makeatother
    

    or

    \makeatletter
    \expandafter\def\expandafter\@afterheading\expandafter{\@afterheading\mbox{}}
    \makeatother
    

    like in this expandafter example.