LaTeX/Customizing Page Headers and Footers

Page styles in Latex terms refers not to page dimensions, but to the running headers and footers of a document. These headers typically contain document titles, chapter or section numbers/names, and page numbers.

Standard page styles
The possibilities of changing the headers in plain Latex are actually quite limited. There are two commands available: will apply the specified style to the current and all subsequent pages, and  will only affect the current page. The possible styles are:

The commands  and  can be used to set the content of the headings by hand. The following commands placed at the beginning of an article document will set the header of all pages (one-sided) to contain "John Smith" top left, "On page styles" centered and the page number top right:

There are special commands containing details on the running page of the document.

Note that and  convert the names to uppercase, whichever was the formatting of the text. If you want them to print the actual name of the chapter without converting it to uppercase use the following command:

Now and  will just print the name of the chapter and section, without number and without affecting the formatting. Note that these redefinitions must be inserted after the first call of. The standard book formatting of the is:

Watch out: if you provide long text in two different "parts" only in the footer or only in the header, you might see overlapping text.

Moreover, with the following commands you can define the thickness of the decorative lines on both the header and the footer:

The first line for the header, the second for the footer. Setting it to zero means that there will be no line.

Plain pages issue
An issue to look out for is that the major sectioning commands (, or ) specify a. So, if you wish to suppress all styles by inserting a at the beginning of your document, then the style command at each section will override your initial rule, for those pages only. To achieve the intended result one can follow the new section commands with. The command, however, cannot be fixed this way, because it sets the page style, but also advances to the next page, so that  cannot be applied to that page. Two solutions:
 * simply write in the preamble. This package will make  have the same effect as, effectively suppressing page numbering when it is used.
 * Use as described below.

The tricky problem when customizing headers and footers is to get things like running section and chapter names in there. Standard LaTeX accomplishes this with a two-stage approach. In the header and footer definition, you use the commands and  to represent the current section and chapter heading, respectively. The values of these two commands are overwritten whenever a chapter or section command is processed. For ultimate flexibility, the command and its friends do not redefine  and  themselves. They call yet another command (,, or ) that is responsible for redefining and , except if they are starred -- in such a case,  must be used inside the sectioning command if header and footer lines are to be updated.

Again, several packages provide a solution:
 * an alternative one-stage mechanism is provided by the package );
 * will handle the process its own way.

Customizing with fancyhdr
To get better control over the headers, one can use the package written by Piet van Oostrum. It provides several commands that allow you to customize the header and footer lines of your document. For a more complete guide, the author of the package produced this documentation.

To begin, add the following lines to your preamble:

You can now observe a new style in your document.

The needs to be 13.6pt or more, otherwise you will get a warning and possibly formatting issues. Both the header and footer comprise three elements each according to its horizontal position (left, centre or right).

The styles supported by :
 * the four LaTeX styles;
 * defines a new header for all pages but plain-style pages such as chapters and titlepage;
 * is the same, but for absolutely all pages (this page style is deprecated, for new documents a combination of and  should be used instead, see section 26 of the manual).

Style customization
The styles can be customized with specific commands. Those two styles may be configured directly, whereas for LaTeX styles you need to make a call to the command.

To set header and footer style, provides three interfaces. They all provide the same features, you just use them differently. Choose the one you like most.


 * You can use the following six commands (these commands are deprecated, use the new ones defined below).

Hopefully, the behaviour of the above commands is fairly intuitive: if it has head in it, it affects the head etc, and obviously, l, c and r means left, centre and right respectively.


 * You can also use the command for header and  for footer. They work in the same way, so we'll explain only the first one. The syntax is:

You can use multiple selectors optionally separated by a comma. The selectors are the following: so will refer to the center of the even pages and to the right side of the odd pages.


 * is a merge of and, hence the name. There are two additional selectors  and  to specify the header or the footer, respectively. If you omit the  and the , it will set the fields for both.

These commands will only work for and. To customize LaTeX default style you need the command. See below for examples.

For a clean customization, we recommend you start from scratch. To do so you should erase the current pagestyle. Providing empty values will make the field blank. So

will just delete the current heading/footer configuration, so you can make your own.

Plain pages
There are two ways to change the style of plain pages like chapters and titlepage.

First you can use the style. If you do so, you can use the command inside  commands like, etc.

When LaTeX wants to create a page with an empty style, it will insert the first argument of, in all the other cases it will use the second argument. For instance:

It has the same behavior of the previous code, but you will get empty header and footer in the title and at the beginning of chapters.

Alternatively you could redefine the plain style, for example to have a really plain page when you want. The command to use is and the argument can contain all the commands explained before. An example is the following:

In that case you can use any style but because it would override your redefinition.

Examples
For two-sided, it's common to mirror the style of opposite pages, you tend to think in terms of inner and outer. So, the same example as above for two-sided is:

This is effectively saying author name is top outer, today's date is top inner, and current page number is bottom outer. Using can make it shorter:

Here is the complete code of a possible style you could use for a two-sided document:

Using one can additionally define multiple styles for one's document that are easy to switch between. Here's a somewhat complicated example for a two-sided book style:

Customizing with scrlayer-scrpage
Package  is part of the KOMA-script bundle. Using this package to customize the headers and footers is recommended with every KOMA-script class. The package can be used with the standard classes as well.

Just loading the package doesn't change the default behavior. Chapter titles are on left hand pages, the section titles on right hand pages. The page number appears in the outer head.

Now, what can we do to customize the headers and footers?

We can use the commands that are available with the package, they are described in more detail in the package documentation.

Following a few examples that may be needed in real documents.

How can one move the page number to the center of the footer and remove the capitalization of the header?
Both, header and footer are separated in an inner, center, and outer part, which can be set independently. The asterisk defines the same content to be on  pages as well. Usually, pages on which a chapter starts, use the style.

How to change to font style in headers and footers?
The package provides an interface similar to the KOMA-script classes. You can add font attribute to the header and footer. The page number can be set independently.

Page n of m
Some people like to put the current page number in context with the whole document. LaTeX only provides access to the current page number. However, you can use the package to find the total number of pages, like this:

Note the capital letters. Also, add a backslash after to ensure adequate space between the page number and 'of'. And recall, when using references, that you have to run LaTeX an extra time to resolve the cross-references.

Customizing with titleps
takes a one-stage approach, without having to use or.

For example:

defines a pagestyle named  with the page at the left on even pages and at the right on odd pages, the chapter title at the center of even pages, and so on.

With titleps all the format is done in the page style, and not partly when the mark is emitted and partly when the mark is retrieved. The following example is similar to the previous one, but elements are coloured:

de:LaTeX-Kompendium:_Kopf-_und_Fu%C3%9Fzeile