# Two sections on one page make fancyhdr takes the second one as page header

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).

Here is the code for the above image:

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

\begin{document}
\section{Introduction}
\lipsum[2]
\section{Overview}
\lipsum[2]
\end{document}

-
In typography, this is considered to be the correct behavior. The header refers to the section that ends the page. –  tohecz Feb 8 '13 at 16:59

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):

\documentclass[oneside]{article}
\usepackage{titleps,lipsum}% http://ctan.org/pkg/{titleps,lipsum}
\newpagestyle{main}{%
{\thepage}% centre
}
\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.

-
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} } } –  Flying Rocket Feb 9 '13 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 '13 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! –  Flying Rocket Feb 9 '13 at 20:31