Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
In typography, this is considered to be the correct behavior. The header refers to the section that ends the page. –  yo' Feb 8 '13 at 16:59

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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