Headers and footers

This article demonstrates how to modify document headers and footers using the fancyhdr package. Another option for customizing headers and footers, addressed in the companion article, How does LaTeX typeset headers and footers?, 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:

If you wish to skip the introductory material, jump to the section on the fancyhdr package. As noted, much more technical detail is contained in the companion article How does LaTeX typeset headers and footers? 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:

which are used via the \documentclass command:

\documentclass[⟨options⟩]⟨class⟩> 

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:

\documentclass[twoside]article> 
\documentclass[twoside]report> 

Default ⟨options⟩ of document classes

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

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:

Default page styles of standard document classes

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

Setting page styles

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

The style of page numbers is set with the command \pagenumbering ; for example, \pagenumbering 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:

Headers and footers in standard LaTeX document classes and page styles

As noted, LaTeX provides several built-in 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

\documentclassarticle> % Choose a conveniently small page size \usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]geometry> \usepackagelipsum>% for some dummy text \titleAn article class example> \authorOverleaf> \begindocument> \maketitle \sectionIn the beginning. > \lipsum[2] \sectionAnother section> \lipsum[1] \sectionYet another> \lipsum[1] 

Default report class headers and footers

\documentclassreport> % Choose a conveniently small page size \usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]geometry> \usepackagelipsum>% for some dummy text \titleA report class example> \authorOverleaf> \begindocument> \maketitle \chapterOne> \sectionIn the beginning. > \lipsum[2] \sectionAnother section> \lipsum[1] \sectionYet another> \lipsum[1] 

Default book class headers and footers

\documentclassbook> % Choose a conveniently small page size \usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]geometry> \usepackagelipsum>% for some dummy text \titleMemoirs of a \TeX<> user> \authorOverleaf> \begindocument> \frontmatter \maketitle This is frontmatter which uses Roman numerals. \mainmatter \chapterWhere do I start> \lipsum[4] \sectionIn the beginning. > \lipsum[1] \sectionYet another section> \lipsum[1] \chapterThings I remember> \sectionOh and a further section> \lipsum[1] 

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 notes use of the scrlayer-scrpage package, rather than fancyhdr, for improved integration with the KOMA-script document classes. Additionally, the memoir document class 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:

\usepackage[⟨options⟩]fancyhdr> 

where ⟨options⟩ are explained in the package documentation.

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: