fancyhdr
Provides comprehensive control over page header and footer customization, enabling flexible page layout designs and consistent document styling.
Overview
Offers sophisticated tools for creating and managing custom page layouts through header and footer manipulation. The package extends far beyond LaTeX's default page styling capabilities, giving users precise control over content placement and formatting.
- Allows separate customization of left, center, and right components in both headers and footers
- Supports different styles for odd and even pages, perfect for two-sided documents
- Enables dynamic content including page numbers, chapter titles, and custom text
- Commonly used in thesis documents, books, reports, and professional documentation where consistent, polished page styling is essential
- Features automatic handling of special pages like chapter starts while maintaining design flexibility
Getting Started
To use fancyhdr
, include it in your document preamble:
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
After loading the package, you need to set \pagestyle{fancy}
to activate the fancy page style. You can then customize headers and footers using commands like \fancyhead
and \fancyfoot
.
Examples
Basic customization of headers and footers with fancyhdr.
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\fancyhf{} % Clear all header and footer fields
\fancyhead[L]{My Document Title}
\fancyhead[R]{\today}
\fancyfoot[C]{Page \thepage}
\begin{document}
\section{Introduction}
\lipsum[1-5] % Generate sample text
\end{document}
Different headers for odd and even pages (two-sided document).
\documentclass[twoside]{article}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\fancyhf{} % Clear all header and footer fields
\fancyhead[LE,RO]{\thepage} % Left on even pages, right on odd pages
\fancyhead[RE]{Chapter \thesection} % Right on even pages
\fancyhead[LO]{\leftmark} % Left on odd pages
\fancyfoot[C]{Draft Version}
\begin{document}
\section{First Section}
\lipsum[1-3]
\section{Second Section}
\lipsum[4-6]
\end{document}
Custom header with line and chapter/section information.
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\fancyhf{} % Clear all header and footer fields
% Redefine header line thickness and style
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}
% Custom header content
\fancyhead[L]{\textbf{\thesection}}
\fancyhead[C]{\textit{\leftmark}}
\fancyhead[R]{Author Name}
% Custom footer content
\fancyfoot[L]{Created: \today}
\fancyfoot[C]{Confidential}
\fancyfoot[R]{Page \thepage}
\begin{document}
\section{Introduction}
\lipsum[1-3]
\section{Methodology}
\lipsum[4-6]
\section{Results}
\lipsum[7-9]
\end{document}