Table of Contents

TexLive Headers and Footers

Page headers and footers contain running titles, page numbers, and author names. The fancyhdr package provides flexible control over them.

\usepackage{fancyhdr}
\pagestyle{fancy}
 
\lhead{Left Header}
\chead{Center Header}
\rhead{Right Header}
 
\lfoot{Left Footer}
\cfoot{\thepage}        % page number
\rfoot{Right Footer}
 
\begin{document}
% Page content
\end{document}

\lhead, \chead, \rhead set left, center, and right headers. \lfoot, \cfoot, \rfoot set footers. \thepage inserts the current page number automatically.

Page styles control where headers/footers appear:

\pagestyle{fancy}       % enable fancy headers/footers
\pagestyle{plain}       % just page number in footer (default)
\pagestyle{empty}       % no headers or footers
\pagestyle{headings}    % section titles in header

First page different from others (e.g., no header on title page):

\fancypagestyle{plain}{
  \fancyhf{}             % clear all fields
  \cfoot{\thepage}       % only page number in footer
}
 
\begin{document}
\maketitle               % uses plain style automatically
 
\pagestyle{fancy}        % subsequent pages use fancy
 
Your content...
\end{document}

Horizontal lines above/below headers and footers:

\renewcommand{\headrulewidth}{0.4pt}  % thin line under header
\renewcommand{\footrulewidth}{0.4pt}  % thin line above footer

Set to 0pt to remove the line.

Section titles in headers:

\usepackage{fancyhdr}
\pagestyle{fancy}
 
\rhead{\thesection. \leftmark}  % current section title
\cfoot{\thepage}

\leftmark contains the current section title (or chapter title in books). This is updated automatically as you move through sections.

Clearing fields:

\fancyhf{}               % clear all headers and footers
\cfoot{\thepage}         % then set only what you want

\fancyhf{} clears everything; then set individual fields.

Different headers for odd/even pages (for double-sided documents):

\lhead[\textrm{Even Page}]{\textrm{Odd Page}}  % [even] {odd}

This is useful for book formatting where even pages have one style, odd pages another.

Margins and spacing: Adjust header/footer distances from the page edge with lengths like \headheight, \headsep, \footskip. Usually defaults are fine, but if you get warnings, increase these:

\setlength{\headheight}{15pt}
\setlength{\headsep}{0.5in}