5

I have two sections on one page. Unfortunately fancyhdr takes the second one as the page header, which will result in something like seen in the image below.

I want to have the first section as the header title (in this case: Introduction).

enter image description here

Here is the code for the above image:

\documentclass[12pt, oneside]{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{\fancyplain{}{\leftmark }}
\rhead{}
\usepackage{lipsum} %only for dummy text

\begin{document}
    \section{Introduction}
        \lipsum[2]
    \section{Overview}
        \lipsum[2]
\end{document}
1
  • In typography, this is considered to be the correct behavior. The header refers to the section that ends the page.
    – yo'
    Feb 8, 2013 at 16:59

1 Answer 1

5

titleps - as an alternative to fancyhdr - provides \toptitlemarks and \bottitlemarks to identify the top/bottom titles on a page, respectively. It should not be difficult to switch to titleps, in my opinion. Here's a short example that illustrates this (click the image to enlarge):

enter image description here

\documentclass[oneside]{article}
\usepackage{titleps,lipsum}% http://ctan.org/pkg/{titleps,lipsum}
\newpagestyle{main}{%
  \sethead
    {\toptitlemarks \thesection \quad \sectiontitle}% left
    {\thepage}% centre
    {\bottitlemarks \thesection \quad \sectiontitle}% right
  \setheadrule{.4pt}% Regular header rule
}
\pagestyle{main}
\begin{document}
\section{Introduction}
\lipsum[1-3]
\section{Overview}
\lipsum[4-6]
\section{Conclusion}
\lipsum[5-9]
\end{document}

The above MWE produces 3 pages with headers:

1 Introduction       1           2 Overview
...
2 Overview           2         3 Conclusion
...
3 Conclusion         3         3 Conclusion
...

Obviously page 3 presents a problem. However, you might not be interested in a dictionary-style header (showing both the first and last section on the page).

See the titleps documentation (section 4. Marks, p 4) for more information.

3
  • Thank you very much for your detailed answer. Can I still use fancyhdr while using titleps? Because I do have a different header style for my titlepage: \fancypagestyle{firstPageStyle} { \fancyhead[R]{ \includegraphics[width=\textwidth]{images/header} } }` Feb 9, 2013 at 10:26
  • @FlyingRocket: No; these packages are to be used exclusively (one or the other). However, titleps also allows you to make page styles (however many you want), just like fancyhdr. In my MWE, I've created the main page style using \newpagestyle{main}{<page style stuff>}. You can add \newpagestyle{firstPageStyle}{<different stuff>}.
    – Werner
    Feb 9, 2013 at 14:46
  • Thank you for your comment. Now I can use titleps as it can also handle custom page styles :). Thank you for your help! Feb 9, 2013 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .