# Manually setting page headers using fancyhdr [duplicate]

How do I manually set page headers? In my example below, all the page headers are the same as the last instance of \rhead{7}. Is there any way to renew the page header to the first instance of \rhead{#} on that specific page?

As an example, say I typeset a bible and after compilation a page happens to contain a bit of overflow from Genesis 1, the whole of Genesis 2, and the first bit of Genesis 3 and say I respectively evoked \rhead{Genesis 1}, \rhead{Genesis 2}, and \rhead{Genesis 3} after the chapter definitions in the source, I would want the header of the page to then be Genesis 1.

As a bonus, it would be even nicer if the header contains the accumulation of chapters on the page so that the header is Genesis 1, 2, 3, but I am not sure if that is easily achievable.

This process also don't have to be fully automatic; my document is the output of a python script and I can iteratively inject complex latex code anywhere in the document as my heart pleases.

\documentclass[afrikaans, english, oneside,openany,a4paper]{book}
\usepackage{parcolumns}
\setlength{\parindent}{0.0em}
\setlength{\parskip}{0.0em}
\usepackage{xunicode}
\usepackage[T1]{fontenc}
\usepackage[margin=1.0in]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
0
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\\ \\
\\ \\
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\\ \\
\end{document}


## marked as duplicate by Johannes_B, user31729, Zarko, Stefan Pinnow, JesseJan 8 '17 at 13:55

• Don't use \rhead everywhere. Use e.g. \rhead{\rightmark} in the preambel and \markright{whatever} in the document. – Ulrike Fischer Oct 7 '14 at 12:17
• Thanks Ulrike, the results are now much better; my example's header now results in Genesis 2, which is better than Genesis 3 (the last chapter on the page), but still not Genesis 1 as I desired (the overflowed text from the previous page's last chapter). Any-case, this might actually be a better and more standard solution than what I initially wanted. – Simon Streicher Oct 7 '14 at 12:57

A possible solution using scrlayer-scrpage.

\documentclass[a5paper]{article}
\usepackage[automark,markcase=noupper]{scrlayer-scrpage}
\clearpairofpagestyles
\cfoot{\pagemark}
\usepackage{blindtext}
\usepackage{geometry}
\begin{document}
\setcounter{secnumdepth}{-1}
\section{Genesis 1}
\blindtext
\section{Genesis 2}
\blindtext
\section{Genesis 3}
\blindtext
\clearpage
\section{Wombat 1}
\blindtext
\section{Wombat 2}
\blindtext[2]
\section{Wombat 3}
\blindtext
\end{document}