# Section break that displays content iff it occurs in middle of a page

I'm trying to create a section break that will display a separator when it occurs in the middle of a page, but display nothing if it lies at the top or bottom of a page, where there's nothing to be separated.

The closest I've been able to find is \pfbreak of the memoir class, but this does the inverse of what I want (displays content at the top or bottom, but not in the middle of a page).

I was hoping to pull the code out of the file here (from line 10858, \def\pfbreakOutput seems to be the part of interest) but getting the behaivor I want looks to involve redesigning the output routine, which is well above my head.

Can anyone either suggest a way of changing this to get an \inversepfbreak command as described, or an alternative way of going about this?

Another possibility might be setting up \label{end-of-section} and \label{start-of-next-section}; I would imagine it is possible to do a string comparison on their \pageref's and show/hide the content based on this. I don't think this is will be a good solution though, since you can't determine the page until it has been processed, after which the page breaks will all change anyway if I start adding/removing page separators.

Thanks!

Christopher

• Welcome to TeX.SX! What document class are you using? Is it memoir? – egreg Jun 24 '14 at 9:12
• Hi, and thanks! I'm using book, but switching to memoir wouldn't be a big deal I think. – avy Jun 24 '14 at 9:56

leaders can be used to make rules that get discarded like space:

\documentclass{article}

\let\xsection\section
\renewcommand\section{%
\par
\nobreak\smallskip
\csname @nobreaktrue\endcsname
\xsection}

\begin{document}

\section{aaa}
One two three\par Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three. Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.

\section{aaa}
Red yellow blue. One two three\par Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three. Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.

\section{aaa}
zzzz. One two three\par Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three. Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.
One two three\par Four five six seven eight nine ten.

\end{document}

• That looks perfect, but it doesn't like me using anything except an hrule there -- is it possible to get this working with e.g. an image? – avy Jun 24 '14 at 9:51
• @user56025: It works with boxes too. But you must make the vskip large enough. E.g. \cleaders\hbox{XXX}\vskip12pt – Ulrike Fischer Jun 24 '14 at 10:28
• @UlrikeFischer thanks for answering I was away from my desk:-) – David Carlisle Jun 24 '14 at 10:44