# [Tex/LaTex] Section should automatically start new page if the whole section does not fit on current page

page-breakingsectioningsections-paragraphstitlesec

I would like my sections to start on a new page if they do not fit on the current page. In other words: if a section fits on the current page print it, if it does not fit start printing it on the next page.

I would like this to be done automatically.

\usepackage{titlesec} seems to be the solution, but I can not get it to do the job.

• Should it be done with titlesec? how ?
• Is there a better approach?

There is a simple solution that does require only a single pass ...

\documentclass{article}

\newcommand\mysection{\vfil\penalty-9999\vfilneg\section}

\usepackage{lipsum}

\begin{document}
\mysection{A} \lipsum[3]
\mysection{B} \lipsum[1-2]
\mysection{C} \lipsum[5]
\end{document}