0

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}
\\ \\
1\rhead{1}
\vspace{100 mm}
\\ \\
2\rhead{2}
\\ \\
3\rhead{3}
\\ \\
4\rhead{4}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
5\rhead{5}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
\vspace{100 mm}
\\ \\
6\rhead{6}
\\ \\
7\rhead{7}
\end{document}
  • 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
1

A possible solution using scrlayer-scrpage.

simonstreicherBible

\documentclass[a5paper]{article}
\usepackage[automark,markcase=noupper]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\rightfirstmark}
\ohead{\rightbotmark}
\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}

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