Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Welcome to TeX.SX! What document class are you using? Is it memoir? –  egreg Jun 24 at 9:12
    
Hi, and thanks! I'm using book, but switching to memoir wouldn't be a big deal I think. –  user56025 Jun 24 at 9:56
add comment

1 Answer 1

up vote 6 down vote accepted

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

\documentclass{article}

\addtolength\textheight{-24\baselineskip}

\let\xsection\section
\renewcommand\section{%
\par
\bigskip\leaders\hrule\vskip1pt
\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}
share|improve this answer
    
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? –  user56025 Jun 24 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 at 10:28
    
This works great, thank you! –  user56025 Jun 24 at 10:41
    
@UlrikeFischer thanks for answering I was away from my desk:-) –  David Carlisle Jun 24 at 10:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.