7

This is a follow up question to Re-displaying section headings after page-breaks. The top answer by Werner works, but not when the package titlesec is loaded. Is another solution possible which does not conflict with titlesec?

5

It's almost the same, but without the need of \patchcmd; just use titlesec's facilities.

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter

\titleformat{name=\section}
  {\normalfont\bfseries\Large}
  {\thesection}
  {1em}
  {\gdef\@section@title@{\thesection\quad#1 (continued)}#1}

\titleformat{name=\section,numberless}
  {\normalfont\bfseries\Large}
  {}
  {0pt}
  {\gdef\@section@title@{#1 (continued)}#1}

\titlespacing{\section}
  {0pt}
  {3ex plus 2ex minus 1ex}
  {1ex plus .5ex minus .5ex}

\let\@section@title@\relax% Sectional heading storage
\def\print@section@title@{%
  {\noindent\normalfont\bfseries\Large\@section@title@}\par\vspace{1ex plus .5ex minus .5ex}%
}
\EveryShipout{%
  \ifdim\pagetotal>\pagegoal% There is content overflow on this page
    \aftergroup\print@section@title@% Reprint/-insert sectional heading
  \fi%
}
\makeatother
\begin{document}
\section{A section}\lipsum[1-6]
\subsection{A subsection}\lipsum[7-14]
\end{document}

The definition of \print@section@title@ should reproduce the section title's format.

enter image description here

  • I think there's a '}' missing in \titleformat{name=\section,numberless} {\normalfont\bfseries\Large} {} {0pt} {\gdef\@section@title@{#1 (continued)#1}after '(continued)'. – twsh Mar 10 '14 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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