TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When fancyhdr prints the header and footer, I believe it uses the following order:

  1. Print header
  2. Print page
  3. Print footer

The problem with this order is that when you have a section in the middle of the page, say, section 4, but you want to print the section name of section 3 in the footer, the declared pagestyle with lfoot through rfoot and \section (embedded in a macro for variable output across the document) will print the section name which is closest to the footer, instead of the section which is at the top of the page.

So, without killing this process of automated footer output (namely the name of the current section at the footer), how can I get the section at the top of the page printed in my footer?


% I want these packages to remain intact with whatever change you're proposing

% Footer

% Command for pageref for page of last page in footer
\cfoot{\thepage /\pageref{LastPage}\hyperlink{page.\getpagerefnumber{anchor.lastpage}}{ $\rightarrow$}}

% ToC name change

% Global pagestyle commands fancyhdr
                \rfoot{\hyperlink{page.1}{$\leftarrow$ Page 1}}
\fancypagestyle{plain}{% Declare plain page style to also print footer on the first page of the document
\cfoot{\thepage /\pageref{LastPage}\hyperlink{page.\getpagerefnumber{anchor.lastpage}}{ $\rightarrow$}}

% Cross-referencing

% Title settings (empty in MWE)


% Footer section name - Declare after ToC to keep section numbering and ToC intact    

% Set footer style

\section{Week 1 - Intro \textcolor{blue}{\textbf{R}}}
\subsubsection{Objecten met \'e\'en getal}



\section{Week 2 - Data sets genereren}

% Anchor on last page for rfoot

share|improve this question
up vote 2 down vote accepted

To accomplish what you want you need the extramarks add-on to fancyhdr.



\section{Section A}


\section{Section B}

\section{Section C}



share|improve this answer

Your Answer


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.