> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/formatting/02-headers-and-footers.md).

# Headers and footers

## Introduction and overview

This article demonstrates how to modify document headers and footers using the [fancyhdr package](https://ctan.org/pkg/fancyhdr?lang=en). Another option for customizing headers and footers, addressed in the companion article, [*How does LaTeX typeset headers and footers?*](/latex/in-depth-articles/23-how-does-latex-typeset-headers-and-footers.md), is to dig deeper into LaTeX code to define new page styles or redefine appropriate low-level commands.

Here, we start with an overview of some basic LaTeX features which define default headers and footers used within a document:

* [document classes](#document-classes)
* [LaTeX page styles](#latex-page-styles)

If you wish to skip the introductory material, jump to [the section on the `fancyhdr` package](#using-the-fancyhdr-package). As noted, much more technical detail is contained in the companion article [*How does LaTeX typeset headers and footers?*](/latex/in-depth-articles/23-how-does-latex-typeset-headers-and-footers.md) which explores and explains the low-level, mark-based, mechanisms used by TeX engines to create headers and footers—and why the `\mark` command is needed.

### LaTeX document classes

Different types of LaTeX document are created using *document classes*; for example, LaTeX provides a number of standard classes:

* `book`
* `report`
* `article`
* `letter`

which are used via the `\documentclass` command:

```latex
\documentclass[⟨options⟩]{⟨class⟩}
```

where:

* `⟨class⟩` could be one of the standard types (`book`, `report`, `article`, `letter`) or one [contributed by individuals and institutions](https://www.ctan.org/topic/class).
* `⟨options⟩` are settings used to configure a particular instance of the document `⟨class⟩`. The available `⟨options⟩` depend on the `⟨class⟩` being used.

#### One- or two-sided documents

If a LaTeX document class supports different layouts for left-facing pages (even page numbers) and right-facing pages (odd page numbers) the document’s headers and footers are usually different on left- and right-facing pages. Defaults for the standard document classes are:

* `book`: two-sided
* `article` and `report`: single-sided but can become two-sided by using the option `twoside`; for example:

```latex
\documentclass[twoside]{article}
```

or

```latex
\documentclass[twoside]{report}
```

#### Default ⟨options⟩ of document classes

LaTeX applies a set of default `⟨options⟩` to each of the standard document classes:

* `article`: default `⟨options⟩` are `letterpaper,10pt,oneside,onecolumn,final`
* `report`: default `⟨options⟩` are `letterpaper,10pt,oneside,onecolumn,final,openany`
* `book`: default `⟨options⟩` are `letterpaper,10pt,twoside,onecolumn,final,openright`
* `letter`: default `⟨options⟩` are `letterpaper,10pt,oneside,onecolumn,final`

Document classes also provide commands which enable users to structure their documents into logical divisions such as parts, chapters, sections, subsections and so forth. As you might expect, the `book` class has a rich set of document structuring commands.

### LaTeX page styles

In LaTeX, the default format of a document’s headers and footers are determined by the *page style* being used. Several predefined page styles are provided by LaTeX:

* `empty`: no headers or footers on pages
* `plain`: no page headers, footers consist of a centered page number
* `headings`: no footers, headers contains class-specific information and page number
* `myheadings`: no footers, headers contains page number and user-supplied information

#### Default page styles of standard document classes

Unless the user specifies otherwise, the standard document classes apply a default page style:

* the `article` and `report` classes use `plain`
* the `book` class uses `headings`

#### Setting page styles

Core LaTeX provides two commands to change (set) the page style:

* `\pagestyle{⟨style⟩}`: sets the style of the current page, and all subsequent pages, to `⟨style⟩`
* `\thispagestyle{⟨style⟩}`: sets style of the current page only to `⟨style⟩`

The style of page numbers is set with the command `\pagenumbering{⟨numberstyle⟩}`; for example, `\pagenumbering{roman}` typesets page numbers in lowercase Roman numerals: i, ii, iii...

### LaTeX page layout

Because headers and footers form part of the overall page layout/design it can be helpful to understand a little more about LaTeX's model of page layout; the following Overleaf articles might be of interest:

* for an introduction to LaTeX page layout, the Overleaf article [Page size and margins](/latex/formatting/07-page-size-and-margins.md) demonstrates how to use the [**`geometry`** package](https://ctan.org/pkg/geometry?lang=en);
* if you want more detail, we suggest the article [A visual guide to LaTeX’s page layout parameters](/latex/in-depth-articles/04-a-visual-guide-to-latex-s-page-layout-parameters.md).

### Headers and footers in standard LaTeX document classes and page styles

As noted, LaTeX provides several [built-in page styles](#latex-page-styles) used as defaults for the standard document classes. The following short examples demonstrate the default headers and footers produced by standard document classes using LaTeX's default `⟨options⟩` for each class.

#### Default article class headers and footers

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]{geometry}
\usepackage{lipsum}% for some dummy text
\title{An article class example}
\author{Overleaf}
\begin{document}
\maketitle

\section{In the beginning...}
\lipsum[2]

\section{Another section}
\lipsum[1]

\section{Yet another}
\lipsum[1]
```

[Open this **`article`** class example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=An+article+class+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%25+for+some+dummy+text%0A%5Ctitle%7BAn+article+class+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%0A%5Csection%7BIn+the+beginning...%7D%0A%5Clipsum%5B2%5D%0A%0A%5Csection%7BAnother+section%7D%0A%5Clipsum%5B1%5D%0A%0A%5Csection%7BYet+another%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

#### Default report class headers and footers

```latex
\documentclass{report}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]{geometry}
\usepackage{lipsum}% for some dummy text
\title{A report class example}
\author{Overleaf}
\begin{document}
\maketitle
\chapter{One}
\section{In the beginning...}
\lipsum[2]

\section{Another section}
\lipsum[1]

\section{Yet another}
\lipsum[1]
```

[Open this **`report`** class example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+report+class+example\&snip=%5Cdocumentclass%7Breport%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%25+for+some+dummy+text%0A%5Ctitle%7BA+report+class+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Cchapter%7BOne%7D%0A%5Csection%7BIn+the+beginning...%7D%0A%5Clipsum%5B2%5D%0A%0A%5Csection%7BAnother+section%7D%0A%5Clipsum%5B1%5D%0A%0A%5Csection%7BYet+another%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

#### Default book class headers and footers

```latex
\documentclass{book}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]{geometry}
\usepackage{lipsum}% for some dummy text
\title{Memoirs of a \TeX{} user}
\author{Overleaf}
\begin{document}

\frontmatter
\maketitle
This is frontmatter which uses Roman numerals.

\mainmatter
\chapter{Where do I start}
\lipsum[4]

\section{In the beginning...}
\lipsum[1]

\section{Yet another section}
\lipsum[1]

\chapter{Things I remember}

\section{Oh and a further section}
\lipsum[1]
```

[Open this **`book`** class example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+book+class+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%25+for+some+dummy+text%0A%5Ctitle%7BMemoirs+of+a+%5CTeX%7B%7D+user%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cfrontmatter%0A%5Cmaketitle%0AThis+is+frontmatter+which+uses+Roman+numerals.%0A%0A%5Cmainmatter%0A%5Cchapter%7BWhere+do+I+start%7D%0A%5Clipsum%5B4%5D%0A%0A%5Csection%7BIn+the+beginning...%7D%0A%5Clipsum%5B1%5D%0A%0A%5Csection%7BYet+another+section%7D%0A%5Clipsum%5B1%5D%0A%0A%5Cchapter%7BThings+I+remember%7D%0A%0A%5Csection%7BOh+and+a+further+section%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

### Changing headers and footers for “non standard” LaTeX document classes

The packages/commands required to change headers and footers can vary according to the document class being used; for example, [the TeX FAQ](https://texfaq.org/FAQ-fancyhdr#:~:text=The%20scrlayer%2Dscrpage%20package%20provides,and%20has%20several%20predefined%20styles) notes use of the [scrlayer-scrpage](https://ctan.org/pkg/scrlayer-scrpage?lang=en) package, rather than [fancyhdr](https://ctan.org/pkg/fancyhdr?lang=en), for improved integration with the [KOMA-script document classes](https://ctan.org/pkg/koma-script). Additionally, the [memoir document class](https://ctan.org/pkg/memoir?lang=en) contains its own features (user commands) to change headers and footers.

## Using the fancyhdr package

To load the `fancyhdr` package add the following line to your document preamble:

```latex
\usepackage[⟨options⟩]{fancyhdr}
```

where `⟨options⟩` are explained in the [package documentation](http://mirrors.ctan.org/macros/latex/contrib/fancyhdr/fancyhdr.pdf).

### Structure of fancyhdr headers and footers

The following diagram summarises the general structure of headers and footers defined by `fancyhdr` for a two-sided document:

* headers and footers can contain different content on left (even) and right (odd) pages
* headers and footers are structured into three “zones”
  * **L***eft*
  * **C***entre*
  * **R***ight*
* headers and footers can contain an optional rule (line)

In the **L** zone the content is typeset flush left; in the **C** zone it is centred and in the **R** zone it is typeset flush right.

![Diagram showing the structure of fancyhdr headers and footers](/files/zqeLJTeIzpFWzjAe52mv)

Commands provided by `fancyhdr` use single-letter abbreviations, called “coordinates”, to identify specific header and footer zones and page locations:

* **`O`** or **`E`**: to specify \*\*`O`\*\*dd or \*\*`E`\*\*ven pages
* **`H`** or **`F`**: to indicate \*\*`H`\*\*eader or \*\*`F`\*\*ooter
* **`L`**, **`C`** or **`R`**: for the \*\*`L`\*\*eft, \*\*`C`\*\*entre and \*\*`R`\*\*ight “zone” of the header or footer

### Introducing the commands

This section discusses several `fancyhdr` commands used to define the content of headers and footers:

* `\fancyhead[*locations*]{*content*}`
* `\fancyfoot[*locations*]{*content*}`
* `\fancyhf[*locations*]{*content*}`

Each of these commands uses “coordinates” to define header and footer `*locations*` where the `*content*` should appear. Depending on which command you use, (up to) 2 or (up to) 3 coordinates may be required to fully specify the desired `*locations*`.

#### Commands using up to 2 coordinates

The following commands require up to 2 coordinates to specify particular locations in a header or footer:

* `\fancyhead[*locations*]{*content*}`: assumes the `**H**`eader coordinate
* `\fancyfoot[*locations*]{*content*}`: assumes the `**F**`ooter coordinate

where `*locations*` is an optional comma-separated list of positions, specified by 1 or 2 coordinates, in which to place `*content*`.

**Double-sided document example**

The following example is taken from the `fancyhdr` documentation:

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% Set the height and width of the paper
includehead,
nomarginpar,% We don't want any margin paragraphs
textwidth=10cm,% Set \textwidth to 10cm
headheight=10mm,% Set \headheight to 10mm
]{geometry}
\usepackage{fancyhdr}
\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
%... then configure it.
\fancyhead{} % clear all header fields
\fancyhead[RO,LE]{\textbf{The performance of new graduates}}
\fancyfoot{} % clear all footer fields
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{From: K. Grant}
\fancyfoot[CO,RE]{To: Dean A. Smith}
% Some content:
This is page 1.\newpage
This is page 2.
\end{document}
```

[Open this `fancyhdr` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%5Cfancyhead%7B%7D+%25+clear+all+header+fields%0A%5Cfancyhead%5BRO%2CLE%5D%7B%5Ctextbf%7BThe+performance+of+new+graduates%7D%7D%0A%5Cfancyfoot%7B%7D+%25+clear+all+footer+fields%0A%5Cfancyfoot%5BLE%2CRO%5D%7B%5Cthepage%7D%0A%5Cfancyfoot%5BLO%2CCE%5D%7BFrom%3A+K.+Grant%7D%0A%5Cfancyfoot%5BCO%2CRE%5D%7BTo%3A+Dean+A.+Smith%7D%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

The following graphic shows the output produced by this example:

![Double-sided document example created with LaTeX fancyhdr package](/files/Q9j37JmnYXbUZubOOpX8)

**Notes on the commands used**

* **`\fancyhead{}`**: clears the settings for the headers
* **`\fancyfoot{}`**: clears the settings for the footers
* **`\fancyhead[RO,LE]{\textbf{The performance of new graduates}}`**: uses the header locations **`RO`** (\*\*`R`**ight**`O`**dd) and `LE` (**`L`**eft**`E`\*\*ven) to place the content `\textbf{The performance of new graduates}`
* **`\fancyfoot[LE,RO]{\thepage}`**: uses the footer locations **`LE`** (\*\*`L`**eft**`E`**ven) and `RO` (**`R`**ight**`O`\*\*dd) to place the page number output by `\thepage`
* **`\fancyfoot[LO,CE]{From: K. Grant}`**: uses the footer locations **`LO`** (\*\*`L`**eft**`O`**dd) and `CE` (**`C`**entre**`E`\*\*ven) to place the content `From: K. Grant`
* **`\fancyfoot[CO,RE]{To: Dean A. Smith}`**: uses the footer locations **`CO`** (\*\*`C`**entre**`O`**dd) and `RE` (**`R`**ight**`E`\*\*ven) to place the content `To: Dean A. Smith`

**One-sided and two-sided documents**

The [diagram above](#hfstructure) shows the structure of headers and footers for a two-sided document, such as the `book` class, or `article`/`report` classes loaded using the option `twoside`.

**Single-sided document examples**

For *single-sided* documents based on the `article` or `report` classes, all pages are, in effect, right-hand pages so the “coordinates” for `**E**`ven pages do not apply. We also don’t *need* to specify the `**O**` coordinate and can use a single `**L**`, `**C**` or `**R**` value:

```latex
\documentclass{article}
\usepackage[paperheight=16cm, paperwidth=12cm,% Set the height and width of the paper
includehead,
nomarginpar,% We don't want any margin paragraphs
textwidth=10cm,% Set \textwidth to 10cm
headheight=10mm,% Set \headheight to 10mm
]{geometry}
\usepackage{fancyhdr}
\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
\title{Single-sided document}
\author{Overleaf}
\date{August 2022}
\fancyhf{} % clear existing header/footer entries
% We don't need to specify the O coordinate
\fancyhead[R]{Hello}
\fancyfoot[L]{\thepage}
\maketitle
\section{Introduction}
Some content.
\newpage
\section{Continued...}
\end{document}
```

[Open this `fancyhdr` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Single-sided+fancyhdr+package+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%5Ctitle%7BSingle-sided+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cfancyhf%7B%7D+%25+clear+existing+header%2Ffooter+entries%0A%25+We+don%27t+need+to+specify+the+O+coordinate%0A%5Cfancyhead%5BR%5D%7BHello%7D%0A%5Cfancyfoot%5BL%5D%7B%5Cthepage%7D%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0ASome+content.%0A%5Cnewpage%0A%5Csection%7BContinued...%7D%0A%5Cend%7Bdocument%7D)

The `fancyhdr` package issues a warning if you try to specify headers or footers using the `**E**` coordinate within single-sided documents:

```latex
\documentclass{article}
\usepackage[paperheight=16cm, paperwidth=12cm,% Set the height and width of the paper
includehead,
nomarginpar,% We don't want any margin paragraphs
textwidth=10cm,% Set \textwidth to 10cm
headheight=10mm,% Set \headheight to 10mm
]{geometry}
\usepackage{fancyhdr}
\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
\title{Warning without twoside}
\author{Overleaf}
\date{July 2022}
\fancyhead[E]{Hello}% This triggers a warning!
\fancyfoot[E]{\thepage}% This triggers a warning!
\maketitle
\section{Introduction}
Some content.
\newpage
\section{Continued...}
\end{document}
```

[Open this ***erroneous*** `fancyhdr` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+warning+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%5Ctitle%7BWarning+without+twoside%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BJuly+2022%7D%0A%5Cfancyhead%5BE%5D%7BHello%7D%25+This+triggers+a+warning%21%0A%5Cfancyfoot%5BE%5D%7B%5Cthepage%7D%25+This+triggers+a+warning%21%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0ASome+content.%0A%5Cnewpage%0A%5Csection%7BContinued...%7D%0A%5Cend%7Bdocument%7D)

As can be seen in this annotated screengrab:

![An example warning from the fancyhdr package](/files/4XFYlQ54dP1tSSemOh8N)

the example above produces the warnings:

```latex
Package fancyhdr Warning: \fancyhead's `E' option without twoside option is useless on input line 23.
Package fancyhdr Warning: \fancyfoot's `E' option without twoside option is useless on input line 24.
```

**Using a single coordinate in a two-sided document: omitting E and O**

If you use `\fancyhead` or `\fancyfoot` in a two-sided document but omit the **`E`** and **`O`** from a location and use *only 1 coordinate*, **`L`**, **`C`** or **`R`**, the `*content*` will be placed in that location on *even and odd pages*.

**Example**

The following example demonstrates omitting **`E`** and **`O`** from `*locations*` specified in `\fancyhead` and \\`fancyfoot`. It also uses the following commands:

* `\pagestyle{fancy}` to set the page style to one configured by `fancyhdr`
* `\fancyhead{}\fancyfoot{}` are used to clear all headers and footers (see also `\fancyhf{}`)

```latex
\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
%... then configure it.

% Clear all headers and footers (see also \fancyhf{})
\fancyhead{}\fancyfoot{}

% Set the Centre header location but do not specify O or E
\fancyhead[C]{In the centre of the header on all pages: \thepage}

% Set the Left footer location but do not specify O or E
\fancyfoot[L]{On the left of the footer on all pages: \thepage}

% Some content:
This is page 1.\newpage
This is page 2.
```

[Open this `fancyhdr` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%0A%25+Clear+all+headers+and+footers+%28see+also+%5Cfancyhf%7B%7D%29%0A%5Cfancyhead%7B%7D%5Cfancyfoot%7B%7D%0A%0A%25+Set+the+Centre+header+location+but+do+not+specify+O+or+E%0A%5Cfancyhead%5BC%5D%7BIn+the+centre+of+the+header+on+all+pages%3A+%5Cthepage%7D%0A%0A%25+Set+the+Left+footer+location+but+do+not+specify+O+or+E%0A%5Cfancyfoot%5BL%5D%7BOn+the+left+of+the+footer+on+all+pages%3A+%5Cthepage%7D%0A%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

The following graphic is an annotated version of the output produced by this code:

![Using a single fancyhdr coordinate in a two-sided LaTeX document](/files/t5cAU4rSvIz9XfGBKiOk)

As can be seen from this graphic, the following code

```latex
\fancyhead[C]{In the centre of the header on all pages: \thepage}
```

sets the \*\*`C`\*\*entre header location but does not specify if it should appear on \*\*`O`\*\*dd or \*\*`E`\*\*ven pages. The omission of **`O`** and **`E`** coordinates results in the \*\*`C`\*\*entre zone header content appearing on odd and even pages.

In addition, this code fragment

```latex
\fancyfoot[L]{On the left of the footer on all pages: \thepage}
```

sets the \*\*`L`\*\*eft footer location but does not specify if it should appear on odd or even pages. The omission of **`O`** and **`E`** coordinates results in the \*\*`L`\*\*eft zone content appearing in the left zone of the footer appearing on odd and even pages.

**Using a single coordinate in a two-sided document: omitting L, C and R**

If you omit **`L`**, **`C`** and **`R`** from a location in a two-sided document, and use *only 1 coordinate*, **`E`** or **`O`**, the `*content*` will be *placed in all three zones* on the even or odd page pages specified in the location.

**Example**

The following example sets the header and footer for odd and even pages but none of the `*locations*` in the `\fancyhead` and `\fancyfoot` commands specify the “zone”, **`L`**, **`C`** or **`R`**, in which the `*content*` should be placed. Note how the `*content*` is reproduced in all three zones.

```latex
\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
%... then configure it.

% Clear all headers and footers (see also \fancyhf{})
\fancyhead{}\fancyfoot{}

% Set the header and footer for Even
% pages but omit the zone (L, C or R)
\fancyhead[E]{Header: even page \thepage}
\fancyfoot[E]{Footer: even page \thepage}

% Set the header and footer for Odd
% pages but omit the zone (L, C or R)
\fancyhead[O]{Header: odd page \thepage}
\fancyfoot[O]{Footer: odd page \thepage}

% Some content:
This is page 1.\newpage
This is page 2.
```

[Open this `fancyhdr` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%0A%25+Clear+all+headers+and+footers+%28see+also+%5Cfancyhf%7B%7D%29%0A%5Cfancyhead%7B%7D%5Cfancyfoot%7B%7D%0A%0A%25+Set+the+header+and+footer+for+Even%0A%25+pages+but+omit+the+zone+%28L%2C+C+or+R%29%0A%5Cfancyhead%5BE%5D%7BHeader%3A+even+page+%5Cthepage%7D%0A%5Cfancyfoot%5BE%5D%7BFooter%3A+even+page+%5Cthepage%7D%0A%0A%25+Set+the+header+and+footer+for+Odd%0A%25+pages+but+omit+the+zone+%28L%2C+C+or+R%29%0A%5Cfancyhead%5BO%5D%7BHeader%3A+odd+page+%5Cthepage%7D%0A%5Cfancyfoot%5BO%5D%7BFooter%3A+odd+page+%5Cthepage%7D%0A%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

The following graphic is an annotated version of the output produced by this code:

![](/files/h03w7dD0b7mxf7MShxpF)

The following code sets the header and footer for **`E`ven pages but omits a zone coordinate (`L`**, **`C`** or **`R`**):

```latex
\fancyhead[E]{Header: even page \thepage}
\fancyfoot[E]{Footer: even page \thepage}
```

This results in:

* **even-page headers** contain `Header: even page \thepage` in all three header zones (**`L`**, **`C`** and **`R`**)
* **even-page footers** contain `Footer: even page \thepage` in all three footer zones (**`L`**, **`C`** and **`R`**)

The following code sets the header and footer for **`O`dd pages but also omits a zone coordinate (`L`**, **`C`** or **`R`**):

```latex
\fancyhead[O]{Header: odd page \thepage}
\fancyfoot[O]{Footer: odd page \thepage}
```

This produces results similar to those for even pages:

* **odd-page headers** contain `Header: odd page \thepage` in all three header zones (**`L`**, **`C`** and **`R`**)
* **odd-page footers** contain `Footer: odd page \thepage` in all three footer zones (**`L`**, **`C`** and **`R`**)

#### \fancyhf: using up to 3 coordinates

`\fancyhf` is a more general command which can be used to combine specifications for headers and footers. To do this it supports the coordinates **`H`** (for \*\*`H`\*\*eader) and **`F`** (for \*\*`F`\*\*ooter). The general form of the command is

* `\fancyhf[*locations*]{*content*}`

where `*locations*` is a optional comma-separated list of locations, specified by 2 or 3 coordinates, to place `*content*`.

Because this command can specify the content of headers *and* footers you need the third coordinate, **`H`** or **`F`** to fully specify the `*locations*`. For example, to use (refer to) the centre zone of footers on the left-hand (even) pages you would specify this as the three coordinates **`EFC`**:

* \*\*`E`\*\*ven-numbered pages
* \*\*`F`\*\*ooter
* \*\*`C`\*\*entre zone

Note that the order of the coordinates is not important: **`EFC`** produces the same result as **`FEC`** and so forth.

The following example uses `\fancyhf` to place content in the \*\*`C`\*\*entre zones of all headers and footers:

```latex
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[EHC]{Even+Header+Centre}
\fancyhf[EFC]{Even+Footer+Centre}
\fancyhf[OFC]{Odd+Footer+Centre}
\fancyhf[OHC]{Odd+Header+Centre}
\lipsum[1]\newpage\lipsum[1]
```

[Open this `\fancyhf` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+fancyhf+command\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cpagestyle%7Bfancy%7D%0A%5Cfancyhf%7B%7D%0A%5Cfancyhf%5BEHC%5D%7BEven%2BHeader%2BCentre%7D%0A%5Cfancyhf%5BEFC%5D%7BEven%2BFooter%2BCentre%7D%0A%5Cfancyhf%5BOFC%5D%7BOdd%2BFooter%2BCentre%7D%0A%5Cfancyhf%5BOHC%5D%7BOdd%2BHeader%2BCentre%7D%0A%5Clipsum%5B1%5D%5Cnewpage%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

The following graphic is an annotated version of the output produced by the previous example:

![An example using the fancyhdr \fancyhf command](/files/3a9vt9pLqNdfSSCQnerd)

### Examples

#### Using basic rules (lines) in headers and footers

The following rule-related commands are provided by version 4.x of `fancyhdr`:

* **`\headrulewidth`**: macro to define the thickness of a line under the header
* **`\footrulewidth`**: macro to define the thickness of a line above the footer
* **`\headruleskip`**: macro to define the distance between the line and the header text (only available since version 4.0)
* **`\footruleskip`**: macro to define the distance between the line and the footer text
* **`\headrule`** macro to completely redefine header rules (lines)
* **`\footrule`** macro to completely redefine footer rules (lines)
* **`\headwidth`** a length parameter that defines the total width of the headers and footers

**NOTES**:

* the default value of `\headrulewidth` is `0.4pt` and default value of `\footrulewidth` is `0pt` so, by default, that rule is not shown in footers.
* you must use `\renewcommand` to change the width value stored by `\headrulewidth` or `\footrulewidth`
* similarly, use `\renewcommand` to change the space between header or footer text, set by `\headruleskip` or `\footruleskip` respectively

For example:

```latex
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{4pt}
\renewcommand{\headruleskip}{10mm}
\renewcommand{\footruleskip}{10pt}
```

* **Note**: It is *because* the following commands are *macros*
* * `\headrulewidth`
  * `\footrulewidth`
  * `\headruleskip`
  * `\footruleskip`

that you *must* use `\renewcommand` to change values stored by these commands. The following code *will not work*:

```latex
\setlength{\headrulewidth}{2pt}% does not work
\setlength{\headruleskip}{10mm}% also will not work
```

The next example changes rule widths and shows how to modify the distance between rules (lines) and header and footer text—using `\headruleskip` and `\footruleskip`:

```latex
\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
%... then configure it.
\renewcommand{\headruleskip}{10mm}
\renewcommand{\footruleskip}{10pt}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{4pt}
% Some content:
\chapter{Wrangling settings}
\section{Page 1}
This is page 1.
\newpage
\section{Page 2}
This is page 2.
\end{document}
```

[Open this `fancyhdr` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0A%25+Set+%5Cheadheight+to+15mm+to+accommodate%0A%25+value+of+%5Cheadruleskip%0Aheadheight%3D15mm%2C%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%5Crenewcommand%7B%5Cheadruleskip%7D%7B10mm%7D%0A%5Crenewcommand%7B%5Cfootruleskip%7D%7B10pt%7D%0A%5Crenewcommand%7B%5Cheadrulewidth%7D%7B2pt%7D%0A%5Crenewcommand%7B%5Cfootrulewidth%7D%7B4pt%7D%0A%25+Some+content%3A%0A%5Cchapter%7BWrangling+settings%7D%0A%5Csection%7BPage+1%7D%0AThis+is+page+1.%0A%5Cnewpage%0A%5Csection%7BPage+2%7D%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

#### Using fancy rules in headers

The following example is derived from one contained in the `fancyhdr` package documentation which uses the [`fourier-orns` package](https://ctan.org/pkg/fourier?lang=en).

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% Set the height and width of the paper
includehead,
nomarginpar,% We don't want any margin paragraphs
textwidth=10cm,% Set \textwidth to 10cm
headheight=14pt,% Set \headheight to 14pt to accommodate our fancy rule!
]{geometry}
\usepackage{fourier-orns}
\usepackage{fancyhdr}
\renewcommand{\headrule}{%
\vspace{-8pt}\hrulefill
\raisebox{-2.1pt}{\quad\decofourleft\decotwo\decofourright\quad}\hrulefill}
\title{Decorative line}
\author{Overleaf}
\date{August 2022}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\nouppercase{\rightmark\hfill\leftmark}}
\fancyhead[RO]{\nouppercase{\leftmark\hfill\rightmark}}
\fancyfoot[LE,RO]{\hfill\thepage\hfill}
\chapter{Fancy rules!}
\section{Introduction}
This example is taken from the \texttt{fancyhdr} documentation.
\newpage
\section{See the header}
\newpage
\section{Yes, very neat!}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Drawing+fancy+rules+in+headers\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D14pt%2C%25+Set+%5Cheadheight+to+14pt+to+accommodate+our+fancy+rule%21%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfourier-orns%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Crenewcommand%7B%5Cheadrule%7D%7B%25%0A%5Cvspace%7B-8pt%7D%5Chrulefill%0A%5Craisebox%7B-2.1pt%7D%7B%5Cquad%5Cdecofourleft%5Cdecotwo%5Cdecofourright%5Cquad%7D%5Chrulefill%7D%0A%5Ctitle%7BDecorative+line%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cpagestyle%7Bfancy%7D%0A%5Cfancyhf%7B%7D%0A%5Cfancyhead%5BLE%5D%7B%5Cnouppercase%7B%5Crightmark%5Chfill%5Cleftmark%7D%7D%0A%5Cfancyhead%5BRO%5D%7B%5Cnouppercase%7B%5Cleftmark%5Chfill%5Crightmark%7D%7D%0A%5Cfancyfoot%5BLE%2CRO%5D%7B%5Chfill%5Cthepage%5Chfill%7D%0A%5Cchapter%7BFancy+rules%21%7D%0A%5Csection%7BIntroduction%7D%0AThis+example+is+taken+from+the+%5Ctexttt%7Bfancyhdr%7D+documentation.%0A%5Cnewpage%0A%5Csection%7BSee+the+header%7D%0A%5Cnewpage%0A%5Csection%7BYes%2C+very+neat%21%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![An example of creating fancy rules in headers via the fourier-orns package](/files/YGil2kW2VKinmrS0FMAl)

* Notes on commands in this example
  * **`\headrule`**: a macro which defines how to draw the decorative line in the header. Here it is redefined to draw a line containing ornaments from the [`fourier-orns` package](https://ctan.org/pkg/fourier?lang=en).
  * **`\leftmark`** and **`\rightmark`**: these commands are used to obtain “mark data” inserted by LaTeX’s sectioning commands. For a more complete explanation of these commands we recommend the companion article [*How does LaTeX typeset headers and footers?*](/latex/in-depth-articles/23-how-does-latex-typeset-headers-and-footers.md)
  * **`\nouppercase`**: a command provided by the `fancyhdr` package to prevent header or footer text being typeset in uppercase, which is the default style for LaTeX headers and footers

#### fancyhdr warning: \headheight is too small

If you receive the `fancyhdr` warning that `\headheight` is too small you *can* reset it to some value `height` by writing

```latex
\setlength{\headheight}{height}
```

but the [recommended solution is to use the `geometry` package](https://tex.stackexchange.com/a/100408) and apply its `headheight=*height*` option to set the value of `\headheight` to `*height*`.

The following example revisits our earlier book class example and resets `\headheight` to 2cm via `headheight=2cm`:

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% Set the height and width of the paper
includehead,% See below for an explanation
nomarginpar,% We don't want any margin paragraphs
textwidth=10cm,% Set \textwidth to 10cm
headheight=2cm,% Set \headheight to 2cm
showframe % Show the page layout
]{geometry}
\title{Memoirs of a \TeX{} user}
\author{Overleaf}
\begin{document}

\frontmatter
\maketitle
This is frontmatter which uses Roman numerals.

\mainmatter
\chapter{Where do I start}
Chapter 1: A short chapter that ends on page 1.

\chapter{Things I remember}
Chapter 2: Starts on page 3, so \LaTeX{} inserts a ``blank'' page 2.
\end{document}
```

[Open in Overleaf: example to set `\headheight` using the geometry package](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Setting+headheight+using+the+geometry+package\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%25+See+below+for+an+explanation%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D2cm%2C%25+Set+%5Cheadheight+to+2cm%0Ashowframe+%25+Show+the+page+layout%0A%5D%7Bgeometry%7D%0A%5Ctitle%7BMemoirs+of+a+%5CTeX%7B%7D+user%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cfrontmatter%0A%5Cmaketitle%0AThis+is+frontmatter+which+uses+Roman+numerals.%0A%0A%5Cmainmatter%0A%5Cchapter%7BWhere+do+I+start%7D%0AChapter+1%3A+A+short+chapter+that+ends+on+page+1.%0A%0A%5Cchapter%7BThings+I+remember%7D%0AChapter+2%3A+Starts+on+page+3%2C+so+%5CLaTeX%7B%7D+inserts+a+%60%60blank%27%27+page+2.%0A%5Cend%7Bdocument%7D)

**Notes on the geometry package**

The example above uses several options of the `geometry` package:

* `nomarginpar`: specifies that we don't want any margin paragraphs
* `textwidth=10cm`: sets a value (10cm) for `\textwidth`, one of LaTeX’s [page layout parameters](/latex/in-depth-articles/04-a-visual-guide-to-latex-s-page-layout-parameters.md)
* `headheight=2cm`: sets a value (2mm) for `\headheight`, one of LaTeX’s [page layout parameters](/latex/in-depth-articles/04-a-visual-guide-to-latex-s-page-layout-parameters.md)
* `showframe`: draws the page layout

The `geometry` package also provides options which affect how it calculates certain values for LaTeX page layout parameters; for example:

* `includehead`
* `includefoot`

Our example (above) used `includehead` to ensure that the height of the text area is directly affected by changing the value of `headheight`. The following diagram, copied from the `geometry` package documentation, demonstrates how the `includehead` and `includefoot` options affect calculation of the document’s text height:

![Image from geometry package documentation showing how the includehead and includefoot options affect calculation of the document’s text height](/files/scG8QfRsGKssIIjh08LF)

Note that the `geometry` package refers to the height of the text area via the option `textheight` whereas LaTeX uses the similarly-named [`\textheight` page layout parameter](/latex/in-depth-articles/04-a-visual-guide-to-latex-s-page-layout-parameters.md#notes-on-the-page-layout-parameters-and-equations).

#### Footers containing page X of N

Source: edited version of code posted on tex.stackexchange: <https://tex.stackexchange.com/a/282840>.

This example creates a footer which displays the current page number and the total number of pages. It uses the [`lastpage` package](https://ctan.org/pkg/lastpage?lang=en) together with a modified version of the `plain` page style implemented via the `\fancypagestyle` command provided by `fancyhdr`.

```latex
\documentclass[12pt]{article}
\usepackage[paperheight=16cm, paperwidth=12cm,% Set the height and width of the paper
includehead,% See below for an explanation
nomarginpar,% We don't want any margin paragraphs
textwidth=10cm,% Set \textwidth to 10cm
headheight=16pt % Set \headheight to 16pt to avoid fancyhr warnings
]{geometry}
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{lipsum} % just for mock text
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}
\fancypagestyle{plain}{%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyhf{}%
  \fancyfoot[C]{\thepage\ of \pageref{LastPage}}}
\begin{document}
\title{Another fancyhdr demo}
\author{\texttt{tex.stackexchange} \textit{et al}}
\maketitle

\lipsum
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Footers+with+page+X+of+Y\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%25+See+below+for+an+explanation%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D16pt+%25+Set+%5Cheadheight+to+16pt+to+avoid+fancyhr+warnings%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Blastpage%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cusepackage%7Blipsum%7D+%25+just+for+mock+text%0A%5Cpagestyle%7Bfancy%7D%0A%5Crenewcommand%7B%5Cheadrulewidth%7D%7B0pt%7D%0A%5Cfancyfoot%5BC%5D%7B%5Cthepage%5C+of+%5Cpageref%7BLastPage%7D%7D%0A%5Cfancypagestyle%7Bplain%7D%7B%25%0A++%5Crenewcommand%7B%5Cheadrulewidth%7D%7B0pt%7D%25%0A++%5Cfancyhf%7B%7D%25%0A++%5Cfancyfoot%5BC%5D%7B%5Cthepage%5C+of+%5Cpageref%7BLastPage%7D%7D%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctitle%7BAnother+fancyhdr+demo%7D%0A%5Cauthor%7B%5Ctexttt%7Btex.stackexchange%7D+%5Ctextit%7Bet+al%7D%7D%0A%5Cmaketitle%0A%0A%5Clipsum%0A%5Cend%7Bdocument%7D)

#### Creating completely blank pages: no headers or footers

As noted in the [`fancyhdr` package documentation](http://mirrors.ctan.org/macros/latex/contrib/fancyhdr/fancyhdr.pdf), if you create a document using

* the `book` class *without* the `openany` option, or
* the `report` class with the `openright` option

any part (`\part{...}`) and chapter (`\chapter{...}`) pages will start on odd-numbered (right-hand) pages.

Occasionally, LaTeX needs to insert a "blank" page to ensure the next chapter or part page starts on a right-hand page—but that "blank" page will still contain headers that many people consider to be unsightly.

**Example of "blank" pages in a book class document**

The following `book` class example creates 5 pages including 2 right-hand facing chapter pages.

```latex
\begin{document}

\frontmatter
\maketitle
This is frontmatter which uses Roman numerals.

\mainmatter
\chapter{Where do I start}
Chapter 1: A short chapter that ends on page 1.

\chapter{Things I remember}
Chapter 2: Starts on page 3, so \LaTeX{} inserts a ``blank'' page 2.

\end{document}
```

[Open this `book` class example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+blank+pages\&snip=%5Cdocumentclass%7Bbook%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Ctitle%7BMemoirs+of+a+%5CTeX%7B%7D+user%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cfrontmatter%0A%5Cmaketitle%0AThis+is+frontmatter+which+uses+Roman+numerals.%0A%0A%5Cmainmatter%0A%5Cchapter%7BWhere+do+I+start%7D%0AChapter+1%3A+A+short+chapter+that+ends+on+page+1.%0A%0A%5Cchapter%7BThings+I+remember%7D%0AChapter+2%3A+Starts+on+page+3%2C+so+%5CLaTeX%7B%7D+inserts+a+%60%60blank%27%27+page+2.%0A%0A%5Cend%7Bdocument%7D)

As shown in the following annotated graphic, chapter 2 starts on page 3 because LaTeX inserted page 2 which is nominally “blank” but contains an unsightly header.

![Example of blank pages in a book class document](/files/HOjaF5ieWdT4seQpVshl)

A variety of mechanisms—code and packages—can be used to ensure inserted pages, such as page 2 above, are completely blank. Here are some examples:

* use the `emptypage` package by adding the following line to your document's preamble:

```latex
\usepackage{emptypage}
```

* manually insert a blank page at the end of chapter 1 so that chapter 2 will naturally start on a right-hand page, removing the need for LaTeX to force a new page. The following code is suggested in the `fancyhdr` package documentation:

```latex
\clearpage
\begingroup
\pagestyle{empty}\cleardoublepage
\endgroup
```

* similarly, you can create a new page at the end of chapter 1 and set its style to empty using `\thispagestyle{empty}`:

```latex
\newpage\thispagestyle{empty}
```

For more information on, and examples of, using truly blank pages, consult the [TUG FAQ](https://texfaq.org/FAQ-reallyblank) or search for [questions tagged `blank-page` on TeX.stackechange](https://tex.stackexchange.com/questions/tagged/blank-page).

* **TIP**: The TeX FAQ has an entry titled [to get rid of page numbers](https://texfaq.org/FAQ-nopageno%7CHow) which contains some useful advice.

#### Changing the style of a single page

Sometimes is convenient to change the style of a specific page; for example, removing the header and footer from the current chapter page:

```latex
\begin{document}
\maketitle
\chapter{Using different page styles}
\lipsum[1] % via \usepackage{lipsum}
\chapter{Sample Chapter}
\thispagestyle{empty} % remove headers/footers from the chapter page
\lipsum[1]
\clearpage
\section{New section}
\lipsum[1]
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Setting+the+style+of+a+single+page\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%7Blipsum%7D%0A%5Ctitle%7BChanging+the+style+of+a+single+page%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Cchapter%7BUsing+different+page+styles%7D%0A%5Clipsum%5B1%5D+%25+via+%5Cusepackage%7Blipsum%7D%0A%5Cchapter%7BSample+Chapter%7D%0A%5Cthispagestyle%7Bempty%7D+%25+remove+headers%2Ffooters+from+the+chapter+page%0A%5Clipsum%5B1%5D%0A%5Cclearpage%0A%5Csection%7BNew+section%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

#### Multi-line headers or footers

Headers and footers produced by `fancyhdr` can contain multiple lines. The following example is based on the `fancyhdr` documentation but expanded to include a multiline header. This example uses the `datetime2` package command `\DTMnow` to insert the date on which the draft document was typeset. The command `\\` is used to terminate the first line of the header.

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% Set the height and width of the paper
includehead,
nomarginpar,% We don't want any margin paragraphs
textwidth=10cm,% Set \textwidth to 10cm
headheight=25pt,% Set \headheight to 25pt to accommodate the multiline header
]{geometry}
\usepackage{fancyhdr}
\usepackage{datetime2}
\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
%... then configure it.
\fancyhead{} % clear all header fields
\fancyhead[RO,LE]{\textbf{DRAFT} (Typeset \DTMnow)\\\textbf{The performance of new graduates}}
\fancyfoot{} % clear all footer fields
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{From: K. Grant}
\fancyfoot[CO,RE]{To: Dean A. Smith}
% Some content:
This is page 1.\newpage
This is page 2.
\end{document}
```

[Open this `fancyhdr` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Multiline+header+fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D25pt%2C%25+Set+%5Cheadheight+to+25pt+to+accommodate+the+multiline+header%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cusepackage%7Bdatetime2%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%5Cfancyhead%7B%7D+%25+clear+all+header+fields%0A%5Cfancyhead%5BRO%2CLE%5D%7B%5Ctextbf%7BDRAFT%7D+%28Typeset+%5CDTMnow%29%5C%5C%5Ctextbf%7BThe+performance+of+new+graduates%7D%7D%0A%5Cfancyfoot%7B%7D+%25+clear+all+footer+fields%0A%5Cfancyfoot%5BLE%2CRO%5D%7B%5Cthepage%7D%0A%5Cfancyfoot%5BLO%2CCE%5D%7BFrom%3A+K.+Grant%7D%0A%5Cfancyfoot%5BCO%2CRE%5D%7BTo%3A+Dean+A.+Smith%7D%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

The following graphic shows the output produced by this example:

![An example of a multi-line header produced by fancyhdr](/files/vbiSTdlCFxXKOfmVfQq2)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/formatting/02-headers-and-footers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
