I am preparing a book, which is to be divided into Parts, Chapters, and Sections. At the moment, my running headers give the Chapter title (on recto pages), and Section title (on verso). I would like to switch from "Chapter/Section" to "Part/Chapter." I'd be grateful for any suggestions.
2 Answers
Here's one possibility using the standard book
(or report
) class and fancyhdr
; the etoolbox
package was used to patch \@part
so as to grab the part title:
\documentclass{book}
\usepackage[a6paper]{geometry}%just for the example
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{lipsum}%just for the example
\makeatletter
\patchcmd{\@part}
{\markboth{}{}}
{\gdef\parttitle{#1}}
{}
{}
\makeatother
\pagestyle{fancy}
\fancyhf{}
\fancyhead[EL]{\partname~\thepart.\ \parttitle}
\fancyhead[OR]{\nouppercase\leftmark}
\fancyhead[ER,OL]{\thepage}
\begin{document}
\part{Test part one}
\chapter{Test chapter one}
\section{Test section one one}
\lipsum[1-4]
\part{Test part two}
\chapter{Test chapter two}
\section{Test section two one}
\lipsum[1-4]
\end{document}
-
Looking at
book.cls
for chapters, it seems there is an extra space between the dot and the forced space.\@chapapp\ \thechapter. \ %
Commented Jun 17, 2015 at 16:37
Using scrlayer-scrpage
from the KOMA-Script bundle and a bit of hackery...
\documentclass{book}
\usepackage{blindtext}
\usepackage{scrlayer-scrpage}
\automark[chapter]{part}
\usepackage{etoolbox}
\makeatletter
\apptocmd{\@part}{\partmark{#1}}{}{}% thanks to esdd and Markus
\makeatother
\begin{document}
\part{dance}
\chapter{walzing wombat}
\blindtext[10]
\chapter{samba squirrel}
\blindtext[10]
\part{property}
\chapter{busy bee}
\blindtext[10]
\chapter{lazy leguan}
\blindtext[10]
\end{document}
Using the KOMA equivalent, there is no need for hacks; everything works out of the box.
If the header should not be uppercase, use a markcase
option1
to load scrlayer-scrpage
\usepackage[markcase=noupper]{scrlayer-scrpage}
1 - Chapter 5 of the KOMA-Script Manual (2016-06-14), Page 222
-
-
@esdd That works great, but where is it defined? Running grep, it is defined in the classes,
scrlayer-scrpage
definespartmarkformat
. As soon as i know this, i can change the answer ;-) Commented Jun 18, 2015 at 11:12 -
\automark
defines/redefines it for its arguments, see packagescrlayer
. If you have the book see page 469. Unfortunaly this is missing in thescrguide
.– esddCommented Jun 18, 2015 at 11:29 -
-
@esdd You upvoted my answer, i upvoted Gonzalos answer. Where is Bill? Commented Jun 18, 2015 at 12:03