Skip Navigation.

LaTeX: Headers and Footers

LaTeX has built-in settings to control the page style of its default page layouts. With these, the thickness of the rule at thetop of the page can be changed. The header and footer settings are specified with L, C, R for left, center, right; and with O for odd numbered pages and E for even numbered pages. In each setting, the typeface style, size, and font can be specified along with macros with implement various dynamic texts. These are implemented with the \pagestyle command, which can take arguments. The syntax for this command is:
\pagestyle{style_type}

The arguments, or types of style, for the \pagestyle command are:
plain: prints the page numbers on the bottom of the page, in the middle of the footer. This is the default.
headings: prints the current chapter heading and page number in the header on each page, while the footer remains empty.
empty: this sets both the header and the footer to be empty.

When using the \pagestyle command, to change the page style for a single page, use the command: \thispagestyle{style_type}

For more elaborate headers, use the fancy header package, which must be called in your preamble. The command to call this package is:
\usepackage{fancyhdr}

Once the fancyhdr package has been called in the preamble, remember to set the pagestyle to fancy using the command:
\pagestyle{fancy}. If you get errors on text boxes being 'Overfull \vbox' it is because the default space allowed for the heading (1 line of text) is too small to contain the fancy-heading (1 line of text + 1 rule). To change this, add to the space with this command in the preamble: \addtolength{\headheight}{2.5pt}

After calling the fancyhdr package and setting the pagestyle to fancy, the commands to change the appearance of the header are:
\rightmark
\leftmark

With the fancy page style package, the plain variant (called with \fancypagestyle{plain}) can be used to reset some of the parameters. This can be useful when starting a new chapter.

For ultimate flexibility, the \chapter command and its structural friends (section and subsection) do not redefine the \rightmark and \leftmark commands. Instead, the \chapter command and its friends call the other commands specific to the header and footer, which are:
\chaptermark
\sectionmark
\subsectionmark

Two Examples of Using Fancyhdr
Please note that both of these are more complex than what is used in most documents.
\documentclass{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
% with this we ensure that the chapter and section
% headings are in lowercase
\renewcommand{\chaptermark}[1]{markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{} %delete the current section for header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
% make space for the rule
\fancypagestyle{plain}{%
\fancyhead{} %get rid of the headers on plain pages
\renewcommand{\headrulewidth}{0} % and the line
}
\pagestyle{fancy}
\fancyhead{}
\renewcommand\headrulewidth{.1pt}
\fancyhead[LO,RE]{\footnotesize\sffamily\lite\leftmark}
\fancyhead[LE,RO]{\footnotesize\sffamily\lite\itshape\rightmark}
\fancyfoot[c]{}
\fancyfoot[LE,RO]{\setlength{\fboxsep}{2pt}\ovalbox{\footnotesize\sffamily\thepage}}
\fancyfoot[LO,RE]{\footnotesize\sffamily\lite\@title}
\fancypagestyle{plain}{%
\fancyhf{}
\fancyfoot[R]{\setlength{\fboxsep}{2pt}{\ovalbox{\footnotesize\sffamily\thepage}}
\fancyfoot[L]{\footnotesize\sffamily\lite\@title}
\renewcommand{\headerulewidth{0pt}}

Back