1

This is a follow-up to Re-displaying section headings after page-breaks (with titlesec): Instead of repeating the long section heading on any overflowing page, I would like to use the short name (given in [] with the section command).

And while we are at it, I also need to do this on the \subsection level, so I hacked [egreg]'s answer without really knowing what I was doing. See my MWE with these changes to accommodate the subsection level (and happy if improvements are suggested wrt applying this to the subsection level):

\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=\subsection}
  {\normalfont\bfseries\large}
  {\thesubsection}
  {1em}
  {\gdef\@section@title@{\thesubsection\quad#1 (cont'd)}#1}

\titleformat{name=\subsection,numberless}
  {\normalfont\bfseries\large}
  {}
  {0pt}
  {\gdef\@section@title@{#1 (cont'd)}#1}

\titlespacing{\subsection}
  {0pt}
  {2ex plus 1ex minus .5ex}
  {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-5]
\subsection[A shorter one]{A very long, long subsection heading}\lipsum[4-9]
\end{document}

All that is missing is to display "1.1 A shorter one (cont'd)" on top of page 3:

enter image description here

2

Here is a solution. Use \@currentlabelname{}

\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=\subsection}
  {\normalfont\bfseries\large}
  {\thesubsection}
  {1em}
  {\gdef\@section@title@{\thesubsection\quad\@currentlabelname{} (cont'd)}#1}

\titleformat{name=\subsection,numberless}
  {\normalfont\bfseries\large}
  {}
  {0pt}
  {\gdef\@section@title@{\@currentlabelname{} (cont'd)}#1}

\titlespacing{\subsection}
  {0pt}
  {2ex plus 1ex minus .5ex}
  {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-5]
\subsection[A shorter one]{A very long, long subsection heading}\lipsum[4-9]
\end{document}

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.