Headers and Footers in LaTeX

Andrew Bredenkamp

September 25, 2007

For most purposes, the best package for decorating your documents with informative headers and footers is fancyheadings.sty. This gives you potentially twelve fields (left, right and centre; header and footer; odd and even pages). Note that for LaTeX to distinguish between odd and even pages, you need to set the documentclass option so that it knows you want a two-sided document. For this document, we used the following:


Standard page styles

The standard page styles are invoked by means of the \pagestyle{}. The default style is plain, and simply inserts a centred page number at the foot of the page. Other options are:

Page number styles

There are five different page number styles invoked by the \pagenumbering{num_style} command:

The page number for any page is stored in the variable \thepage. Thus the code:

This is page \thepage


This is page 1

Using fancyheadings.sty

As with other packages you can load fancyheadings.sty by putting the following in your preamble:


This defines some new pagestyles which you can invoke with:




The difference between these two is that \fancyplain allows you to retain control over headers and footers even on, say, the first page of a chapter - where normally LaTeX switches to plain.

Since \fancyplain provides a superset of the functionality of fancy, we will simply give an account of the former.

For each page then six `areas' are defined; lhead, chead, rhead for the left, centre and right cells respectively at the top of the page, and similarly lfoot, cfoot, rfoot for the bottom.

For each command, the even (verso) page and odd (recto) page cells are defined separately, so for instance:

\lhead[\thepage]{\thesection}      % Note the different brackets!

would print the page number on the top left of even pages and the section name on the top right. The order would be switched for odd pages.

The \fancyplain command takes two arguments: one for pages LaTeX forces into plain (first pages of chapters, etc), and one for the others. Used in conjunction with \lhead, etc. this gives you full control of every page in your document.

Below is an example of a complete set of header/footer definitions - as used in the preamble of this document:

\lhead[\fancyplain{}{\thepage}]         {\fancyplain{}{\rightmark}}
\chead[\fancyplain{}{}]                 {\fancyplain{}{}}
\rhead[\fancyplain{}{\rightmark}]       {\fancyplain{}{\thepage}}
\lfoot[\fancyplain{}{}]                 {\fancyplain{\tstamp}{\tstamp}}
\cfoot[\fancyplain{\thepage}{}]         {\fancyplain{\thepage}{}}
\rfoot[\fancyplain{\tstamp} {\tstamp}]  {\fancyplain{}{}}

Note that fancyheadings.sty also puts lines to separate headers and footers from the page contents (or live matter).

Other packages

For more information on other packages which might be used for producing headers and footers, please contact us.

Getting fancyheadings.sty

The package is available in http://clwww.essex.ac.uk/latex4ling/archive in the following bundles:

Last Modified September 25, 2007

This page has been accessed Cannot #EXEC file due to lack of EXECUTE permission
times since Mon, 30-Jun-1997