# How to make a header show a continuing section's title?

Goal: I want the reader to know which section he is in, even if a section was page-wrapped.

I've been using \renewcommand{\sectionmark}[1]{\markright{#1}} previously and then \fancyhead[C]{\sffamily \bfseries \rightmark} to make the section's title appear in the header, but sadly this will not consider a continuing section that was wrapped and always show the first new section on the page, if any.

Today I played around a bit and found out about the \afterpage command which I used with

\renewcommand{\sectionmark}[1]{
\markboth{#1}{#1} % make \leftmark and \rightmark refer to the current section title
\afterpage{\markboth{\leftmark}{\rightmark}} % buffer command to \afterpage so that the next page gets the current marks
}


It works for wrapped sections now, but the problem is that a section that starts on a new page with no text prior can not override the previous mark. Since the last section ended before the page ended and the next section is the first thing on a new page, it doesn't make sense to include the previous section's name in the header.

Following is an example that illustrates my problem.

• The page headers should be "test", "test" and "test4".
• Without \afterpage they are "test", "test2" and "test4".
• With \afterpage they are "test", "test", "test3".

Is there a way to make this work?

\documentclass[11pt,a4paper]{scrartcl}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages

% Unicode
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

% Fonts
\usepackage[T1]{fontenc}
\usepackage{lmodern}

% Other packages
\usepackage{afterpage} % runs command after the current page
\usepackage{ifthen}    %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Formatting

\pagestyle{fancy} % set pagestyle
\fancyhf{} % Clear header and footer

\setcounter{secnumdepth}{-1} % Remove numbering from sections

\renewcommand{\sectionmark}[1]{
\markboth{#1}{#1} % make \leftmark and \rightmark refer to the current section title
%\afterpage{\markboth{\leftmark}{\rightmark}} % buffer command to \afterpage so that the next page gets the current section mark
}
\renewcommand{\subsectionmark}[1]{} % ignore subsections

\rightmark
% \ifthenelse{\equal{\rightmark}{\leftmark}} % if
% {\leftmark} % then
% {\rightmark\ --\ \leftmark} % else
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Body
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
% first page's header should be "test"

\section{test}

Text from test section

\newpage
% second page's header should also be "test"

More text from test section

\section{test2}

Text from test2 section

\section{test3}

Text from test3 section

\newpage
% third page's header should be "test4"

\section{test4}

Text from test4 section

\end{document}

• What is the difference between your goal and the usual running headlines? – Keks Dose Nov 2 '14 at 12:55
• Please see the list above my code example. Basically, the default behavior is that the first section on the page is put into the header (\rightmark) but I want the previous section's name to be there if it continues onto the current page. – FichteFoll Nov 3 '14 at 18:48
• Although I cannot answer your question, I believe that the default behavior is stylistically correct. I looked at some library books (fiction, admittedly) in which new chapters began in continuous flow (mid-page, instead of new page). In each case, the heading showed the new chapter number that began there, not the continued chapter number. – RobtA Jun 18 '15 at 23:05

Your goal can be accomplished by 'titleps' package. Below I am including your example with changes. \newpage seems to be interfering with the header. I replaced it with text from 'lipsum' package. In the third section the text is enlarged to force the title of the fourth section to the top of next page. The example compiles into four pages with headers 'test', 'test', 'test3', 'test4'.

\documentclass[11pt,a4paper]{scrartcl}
% Packages
% Unicode
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

% Fonts
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage[outermarks]{titleps} % 'outermarks' assures titles for continuing section
\newpagestyle{main}{
{\bf{\thepage}}}
\pagestyle{main}

% Body
\begin{document}
% first page's header should be "test"

\section{test}
Text from test section\\
\lipsum

% second page's header should also be "test"

More text from test section

\section{test2}
Text from test2 section

\section{test3}

Text from test3 section\\
{\large \lipsum}

% third page's header should be "test4"

\section{test4}
Text from test4 section

\end{document}