fancyhdr to place the page number, section title, date, or document title where you want it.
Quick answer:Use built-in page styles for simple cases and
fancyhdr when you need custom header and footer content.Related topics: Page numbering | Multiple columns | Document classesWhen To Use Page Numbering vs Headers and Footers
Use Page numbering when your main question is:- how to switch between roman and arabic numbers
- how to restart numbering
- how to hide numbers on selected pages
- how to show
Page X of Y
- how to put the page number in a specific place
- how to show chapter or section titles in the header
- how to create different header/footer styles for different pages
- how to control header and footer rules with
fancyhdr
Understanding Page Styles
Default Page Styles
LaTeX provides four built-in page styles:| Style | Description | Header | Footer |
|---|---|---|---|
plain | Default for chapters | Empty | Page number |
empty | Completely blank | Empty | Empty |
headings | Automatic headers | Section/chapter names | Page number |
myheadings | Manual headers | User-defined content | Page number |
The fancyhdr Package
Thefancyhdr package provides complete control over headers and footers.
Basic Setup
Position Specifiers
Advanced Header Customization
Dynamic Content
Conditional Headers
Multi-line Headers
Graphics in Headers
Chapter and Section Information
Automatic Section Headers
Custom Section Marking
Special Page Styles
Title Page Style
Bibliography Style
Headers with Boxes and Borders
Troubleshooting Common Issues
Header Height Problems
Page Break Issues
Best Practices
Professional Formatting
Quick Reference
Essential fancyhdr Commands
| Command | Purpose | Example |
|---|---|---|
\pagestyle{fancy} | Activate fancy headers | Required for customization |
\fancyhf{} | Clear all headers/footers | Start with clean slate |
\fancyhead[L]{text} | Set left header | \fancyhead[L]{\leftmark} |
\fancyfoot[C]{text} | Set center footer | \fancyfoot[C]{\thepage} |
\thispagestyle{style} | Set style for current page | Override default style |
Position Codes
| Code | Meaning | Code | Meaning |
|---|---|---|---|
L | Left | E | Even pages |
C | Center | O | Odd pages |
R | Right | LE | Left on even pages |
Common Variables
| Variable | Content |
|---|---|
\thepage | Current page number |
\leftmark | Chapter name (book) or section name (article) |
\rightmark | Section name (book) or subsection name (article) |
\today | Current date |
Next: Learn about Page numbering for advanced numbering schemes, or explore Multiple columns for overall layout principles.
