TransWikia.com

Fancyhdr for books

TeX - LaTeX Asked on August 29, 2020

I get confused with fancyhdr. Let’s consider this minimal example:

documentclass{book}
usepackage{fancyhdr}
usepackage{lipsum}

pagestyle{fancy}

begin{document}
frontmatter
title{A dummy document}
author{John Doe}
maketitle
tableofcontents
section{Abstract}
lipsum{2}
mainmatter
chapter{Foo}
section{Neo}
lipsum{8-12}
section{Trinity}
lipsum{13-20}
chapter{Bar}
section{Morpheus}
lipsum{21-25}
backmatter
section{Appendix}
lipsum{26}
end{document}

I can note different header/footer styles:

  1. Empty (title page)
  2. No headers + header line + page number in roman (after title page)
  3. No headers + page number in roman (page with tableofcontents)
  4. Headers + page number in roman (other pages in frontmatter)
  5. No headers + page number in arabic (chapter pages)
  6. Headers + page numbers in arabic (other pages in mainmatter)

I don’t really understand (2) and (3). How can I configure all these different configurations?

If I add the following it doesn’t affect the titlepage, the chapter pages and the numbering type:

fancyhead{}
fancyhead[CE]{Even}
fancyhead[CO]{Odd}

How can I configure fancyhdr to:

  • Remove headers/footers on empty pages?
  • Configure header/footers on chapter pages?
  • Configure header/footers on other pages?

One Answer

Remove headers and footers on empty pages

The first question is not about fancyhdr is the behavior of cleardoblepage. In order to remove headers and footers on empty pages I use the following code in the preamble:

makeatletter
  defcleardoublepage{clearpageif@twoside ifoddc@pageelse
  vspace*{fill}
    thispagestyle{empty}
    newpage
    if@twocolumnhbox{}newpagefififi}
makeatother

Configure headers and footers on chapter pages

chapter resets the page style to plain by default. If you want to change the style of this page, try:

chapter{Foo}
thispagestyle{fancy}

Headers and footers in other pages

An example on how to modify headers and footer on other pages:

pagestyle{fancy}
fancyhf{} %clear headers and footers
fancyhead[LE,RO]{thepage} %page number on the left on even pages and the right of odd pages
fancyhead[CO]{leftmark} %chapter name in the center of odd pages
fancyhead[CE]{rightmark} %section title in the center of even pages
renewcommand{headrulewidth}{0pt} %rule width

for this part you need to read a little more, because is difficult to make an example to illustrate every aspect of fancyhdr. Try something basic or the manual.

Answered by Luis Turcio on August 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP