# leavevmode, section and pagebreaks

I have several letters, some very short, in my book, typeset with scrbook, reledmac and \raggedbottom. \chapter is used for years and \section is used for an individual letter.

I need the leavevmode command as it resets some things when the number of letters get too high. But this introduces an unwanted pagebreak after the letter title. Why is that so? And how can I tweak the section command to act as wanted?

MWE:

\documentclass{scrbook}
\usepackage{reledmac}
\usepackage[english]{babel}
\usepackage{blindtext}

\raggedbottom

\begin{document}
\chapter{Letters from 1900}
\leavevmode\pagebreak[3]\section{Letter 1}\nopagebreak[3]
\beginnumbering
\pstart
\blindtext
\pend
\pstart
\blindtext
\pend
\endnumbering

\leavevmode\pagebreak[3]\section{Letter 2}\nopagebreak[3]
\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\leavevmode\pagebreak[3]\section{Letter 3}\nopagebreak[3]
\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}


This is the unwanted result:

• Welcome to TeX.SX! I don't understand why you are using \leavevmode at all?! Of course, if you take out \leavevmode then the problem disappears. What "things" are you trying to reset by using \leavevmode? I suspect that there are better ways to reset them but it is hard to say without knowing what they are... – user30471 Nov 8 '17 at 14:45
• latex never breaks after a section heading but you have \pagebreak[3] almost forcing a page break after the chapter heading and \nopagebreak[3] allowing a page break after section headings. What is the intention of these (just removing them would appear to be the answer) – David Carlisle Nov 8 '17 at 14:53
• Of course I could try to avoid the leavevmode and I don't remember what made me include it in the first place. But when I remove leavevmode from my real project it won't compile the nearly 30.000 lines as it constantly hangs itself. – Martin Mueller Nov 8 '17 at 14:54
• the \leavemode looks wrong but it is the \[no]pagebreak that is allowing the page break. – David Carlisle Nov 8 '17 at 14:55
• I believe it's because reledmac sets it's text as block, thus creating a page break chance. removing the (no)pagebreaks does not work – Martin Mueller Nov 8 '17 at 14:57

## 2 Answers

AFAIK the \leavevmode results in extra vertical space because of an extra but empty paragraph before the section heading. It is not the problem, because it does not allow page breaks after the following \section.

The problem is \pagenumbering after \section. You should add/move \nopagebreak after \pagenumbering:

\documentclass{scrbook}
\usepackage{reledmac}
\usepackage[english]{babel}
\usepackage{blindtext}

\raggedbottom

\begin{document}
\chapter{Letters from 1900}
\leavevmode\pagebreak[3]\section{Letter 1}
\beginnumbering\nopagebreak
\pstart
\blindtext
\pend
\pstart
\blindtext
\pend
\endnumbering

\leavevmode\pagebreak[3]\section{Letter 2}
\beginnumbering\nopagebreak
\pstart
\blindtext
\pend
\endnumbering

\leavevmode\pagebreak[3]\section{Letter 3}
\beginnumbering\nopagebreak
\pstart
\blindtext
\pend
\endnumbering

\end{document}


However, if you really want the extra vertical space before the sections, why do you use \leavevmode to get it instead of using \RedeclareSectionCommand to increase the beforeskip value:

\documentclass{scrbook}
\usepackage{reledmac}
\usepackage[english]{babel}
\usepackage{blindtext}

\raggedbottom
\RedeclareSectionCommand[beforeskip=-10ex plus -1ex minus -.2ex]{section}

\begin{document}
\chapter{Letters from 1900}
\section{Letter 1}
\beginnumbering\nopagebreak
\pstart
\blindtext
\pend
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 2}
\beginnumbering\nopagebreak
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 3}
\beginnumbering\nopagebreak
\pstart
\blindtext
\pend
\endnumbering

\end{document}


If all \beginnumbering should avoid page breaks, you can patch the command:

\documentclass{scrbook}
\usepackage{reledmac}
\usepackage[english]{babel}
\usepackage{blindtext}

\raggedbottom
\RedeclareSectionCommand[beforeskip=-10ex plus -1ex minus -.2ex]{section}

\usepackage{xpatch}
\xapptocmd{\beginnumbering}{\nopagebreak}{}{}

\begin{document}
\chapter{Letters from 1900}
\section{Letter 1}
\beginnumbering
\pstart
\blindtext
\pend
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 2}
\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 3}
\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}


Or you can define a new command:

\documentclass{scrbook}
\usepackage{reledmac}
\usepackage[english]{babel}
\usepackage{blindtext}

\raggedbottom
\RedeclareSectionCommand[beforeskip=-10ex plus -1ex minus -.2ex]{section}

\newcommand\beginnumberingnobreak{\beginnumbering\nopagebreak}

\begin{document}
\chapter{Letters from 1900}
\section{Letter 1}
\beginnumberingnobreak
\pstart
\blindtext
\pend
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 2}
\beginnumberingnobreak
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 3}
\beginnumberingnobreak
\pstart
\blindtext
\pend
\endnumbering

\end{document}


You could also try to detect, whether or not the \beginnumbering is following a \section or another command, that should prevent page breaks:

\documentclass{scrbook}
\usepackage{reledmac}
\usepackage[english]{babel}
\usepackage{blindtext}

\raggedbottom
\RedeclareSectionCommand[beforeskip=-10ex plus -1ex minus -.2ex]{section}

\usepackage{xpatch}
\makeatletter
\xpretocmd{\beginnumbering}{\if@nobreak\let\afterbeginnumbering\nopagebreak\else\let\afterbeginnumbering\relax\fi}{}{}
\xapptocmd{\beginnumbering}{\afterbeginnumbering}{}{}
\makeatother

\begin{document}
\chapter{Letters from 1900}
\section{Letter 1}
\beginnumbering
\pstart
\blindtext
\pend
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 2}
\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 3}
\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}

• I've settled for the new command which does the trick. – Martin Mueller Nov 8 '17 at 19:56

If you remove the \leavevmode and \nopagebreak from the example document then the heading is not at the end of the page as the spurious white paragraphs from \leavevmode have gone, but if you add some more lines as below then the page does break after the heading. This is due to \beginnumbering and if you uncomment the redefinition then a page break at that point is prevented and one extra line stays with the heading.

\documentclass{scrbook}
\usepackage{reledmac}
\usepackage[english]{babel}
\usepackage{blindtext}

\raggedbottom
\let\oldbeginnumbering\beginnumbering

%\def\beginnumbering{\oldbeginnumbering\par\nopagebreak}

\begin{document}
\chapter{Letters from 1900}
\section{Letter 1}
\beginnumbering
\pstart
\blindtext
\pend
\pstart
\blindtext
\pend
\endnumbering

\section{Letter 2}
\beginnumbering
\pstart
\blindtext

a\\ba\\c
\pend
\endnumbering

\section{Letter 3}
\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}