# Re-displaying section headings after page-breaks

I'd like to automatically repeat section headings after a page break. My naive attempt at doing this is to check the page counter and print the extra text whenever the counter increments:

\newcounter{pagecnt}
\setcounter{pagecnt}{\value{page}}

...

\ifnum \value{page} > \value{pagecnt}% are we on a new page?
\setcounter{pagecnt}{\value{page}}% reset counter
\fi%


Except I'm not entirely sure what should 'trigger' this code? Is it possible or desirable to check after every line-break (or every word) if the page has flipped?

-
Perhaps the everyshi (which stands for 'Every Ship Out') package is appropriate here? It sounds like you want similar features provided by the fancyhdr package – cmhughes Mar 11 '12 at 20:59
Thanks, it looks like that's the right track. It seems that I will have to learn more raw tex syntax to get it to format properly, though. – joeyo Mar 11 '12 at 21:31
@cmhughes: Can you provide an answer? – Marco Daniel Apr 14 '12 at 12:04
i interpret this question to mean that you want, at the top of a page when a section continues, the text (for example) "2.3 Title of section (cont.)", and not just the section heading in the running heads. if this is so, then the suggestion that you look at the package everyshi is appropriate. (i'm adding this comment because another comment points to running heads and footers, which is quite different.) – barbara beeton Jul 6 '12 at 21:03
a couple of answers dealing with similar situations mention the afterpage package: changing-the-table-of-contents and insert-text-before-end-of-page-and-at-the-begining-of-the-next-page – barbara beeton Jul 6 '12 at 21:18

The following patch (via etoolbox) saves the sectional content (number, title and font) in a macro that is re-evaluated at page shipout (as supplied by everyshi) if there is text overflow. Overflow is established using the condition

\ifdim\pagetotal>\pagegoal
% <do something>
\fi


that checks whether the gathered page content (of height \pagetotal) extends beyond the allowed total (of height \pagegoal).

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\@sect}% <cmd>
{\@xsect}% <search>
{\noindent#6\@svsec#8\normalfont\ \smash{(continued)}}\par\bigskip}\@xsect}% <replace>
{}{}% <success><failure>
\EveryShipout{%
\fi%
}
\makeatother
\begin{document}
\section{A section}\lipsum[1-6]
\subsection{A subsection}\lipsum[7-14]
\end{document}


The sectional content is captured in \@section@title@ and includes the latest sectional title used (anything from level 1 = \section to level 5 = \paragraph).

Customizations include using only a specific sectional unit (like \section, say). Also, to duplicate the spacing after the sectional header when traditionally used, rather than issuing \bigskip.

The above works in the context of the standard LaTeX document classes (like book, article and report) and may require additional modifications if used in other document classes, or in conjunction with other sectional heading packages.

-
Is there anyway to get this to work when titlesec is loaded? – lyxicon Sep 2 '13 at 4:24
@lyxicon: A completely different solution approach would be required, since titlesec changes the entire sectioning structure. I would suggest asking a follow-up question... – Werner Sep 2 '13 at 5:23
Thanks I'll do that. – lyxicon Sep 2 '13 at 23:57

I think you are looking for a definition of headers and footers. This can be done by packages like fancyhdr or scrpage21. However most document classes defining some predefined style which can be used by the command \pagestyle. Allowed arguments are:

• empty -- no header or footer is printed
• plain -- only the page number is printed
• headings -- depends on the class. e.g. scrartcl will print the section.

1 The documentation of scrpage2 is located in the manual of KOMA

Here a small example:

\documentclass{scrartcl}
\usepackage{kantlipsum}