Headers and footers in LaTeX

The fancyhdr package gives full control over page headers and footers.

Quick answer

latex
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}  % clear defaults

\fancyhead[L]{My Thesis}
\fancyhead[R]{\leftmark}
\fancyfoot[C]{\thepage}

Position keys

Use L, C, R for left/center/right, combined with H (header) or F (footer). For two-sided documents, use O (odd) and E (even).

latex
\fancyhead[L]{left header}
\fancyhead[C]{center header}
\fancyhead[R]{right header}
\fancyfoot[L]{left footer}
\fancyfoot[C]{center footer}
\fancyfoot[R]{right footer}

% Two-sided (thesis):
\fancyhead[LE]{\leftmark}   % even pages, left
\fancyhead[RO]{\rightmark}  % odd pages, right

Automatic section/chapter names

latex
\leftmark   % current chapter (book) or section (article)
\rightmark  % current section (book) or subsection (article)

\fancyhead[R]{\nouppercase{\leftmark}}

Remove the horizontal rule

latex
% Remove header rule:
\renewcommand{\headrulewidth}{0pt}

% Remove footer rule:
\renewcommand{\footrulewidth}{0pt}

% Custom thickness:
\renewcommand{\headrulewidth}{0.4pt}

Plain style on chapter pages

LaTeX automatically switches to plain style on chapter-opening pages. Override it:

latex
\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[C]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
}

Title page without header

latex
\begin{document}
\thispagestyle{empty}  % no header/footer on title page
\maketitle
\newpage
\pagestyle{fancy}      % start fancy from page 2
\end{document}

Related topics