Headers and footers
LaTeX has some predetermined styles that change the way the header and the footer are displayed. The footer and the header can also be customized to fit any particular layout. This article explains how.
Introduction
The information displayed in the footer and the header of a document depends on the page style currently active, these page styles are more notorious in the book document class:
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\pagestyle{headings}
\begin{document}
\chapter{Sample Chapter}
\section{New section}
Hello, here is some text without a meaning. This text should
show what a printed text will look like at this place. If you
read this text, you will get no information. Really? Is there
no information? Is there a difference between this text and some
nonsense like ``Huardest gefburn? Kjift " not at all!...
\end{document}
The command \pagestyle{headings}
sets the page style called headings to the current document. You can see more page styles in the next section
Standard page styles
The standard page styles are invoked in LaTeX by means of the command:
\pagestyle{''style''}
The myheadings pagestyle displays the page number on top of the page in the outer corner.
There are other three page styles:
empty
: Both the header and footer are cleared (blank) in this page style.
plain
: This is the default style. The header is empty and the footer contains page numbers in the centre.
myheadings
: As shown in the introduction,The footer is empty in this page style. The header contains the page number on right side (on even pages) or on left side (on odd pages) along with other user-supplied information; there is an exception for the first page of each chapter, where the footer contains centred page number while the header is blank.
Setting page style for current page only
Sometimes is convenient to specify the page style only for the current page. For instance, to leave a intentionally blank page or to remove the header and footer from the current chapter page:
\chapter{Sample Chapter}
\thispagestyle{empty}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
}ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit es...
\end{document}
Of course, you can replace empty for any of the styles mentioned in the previous section
Style customization in single-sided documents
Styles can be modified beyond the standard layouts by means of fancyhdr. Below is an example.
\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{Overleaf}
\lhead{Guides and tutorials}
\rfoot{Page \thepage}
\begin{document}
\section{First Section}
Hello, here is some text without a meaning. This
text should show what a printed text will look like at
this place. If you read this text, you will get no information.
Really? Is there no information? Is there a difference between
this ...
\end{document}
To customize the footer and header in your document first import the package fancyhdr with
\usepackage{fancyhdr}
After that, the "fancy" style is set by \pagestyle{fancy}
. The command \fancyhf{}
clears the header and footer, otherwise the elements of the default "plain" page style will appear.
Below, a description of the rest of the commands and a few more whose usage is similar.
\rhead{Overleaf}
- Prints the text included inside the braces on the right side of the header.
\lhead{Guides and tutorials}
- Prints the text set inside the braces on the left side of the header.
\chead{ }
- Similar to the previous commands, in this case the text is centred on the header.
\rfoot{Page \thepage}
- Prints the word "Page" and next the page number which is automatically set by
\thepage
on the right side of the footer. See the reference guide for a list of commands that automatically generate content (Section numbers, chapters and so on).
\lfoot{ }
- This prints the parameter passed inside the braces on the left side of the footer.
\cfoot{ }
- Similar to the previous two commands, prints its parameter on the centre of the footer.
Open an example of the fancyhdr package in Overleaf
Style customization in double-sided documents
If your document is double-sided, for example a book, and you need to customize the header and the footer, the recommended commands in this case are \fancyhead
and \fancyfoot
with several selectors passed as parameters. Let's see:
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{Overleaf}
\fancyhead[RE,LO]{Guides and tutorials}
\fancyfoot[CE,CO]{\leftmark}
\fancyfoot[LE,RO]{\thepage}
\begin{document}
\chapter{Using different page styles}
Lorem ipsum dolor sit amet, consectetur adipiscing ...
The selectors that can be passed, inside brackets, to the commands \fancyhead
and \fancyfoot
are:
- E for even page
- O for odd page
- L for left side
- C for centered
- R for right side
For instance, \fancyhead[LE,RO]{Overleaf}
will print the text "Overleaf" on the Left side of the header for Even pages, and the Right side for Odd pages.
For more information on the command \leftmark
and \thepage
used in the previous example see the reference guide.
Open an example of the fancyhdr package in Overleaf
When you are using fancyhdr in your document, there are two decorative lines on both the header and the footer, the latter has 0pt thickness and hence is not visible. It's easy to change that:
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{Overleaf}
\fancyhead[RE,LO]{Guides and tutorials}
\fancyfoot[CE,CO]{\leftmark}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}
\begin{document}
\chapter{Using different page styles}
Lorem ipsum dolor sit amet, consectetur adipiscing ...
There are two additional lines in this example:
\renewcommand{\headrulewidth}{2pt}
- This sets the header line thickness to 2pt.
\renewcommand{\footrulewidth}{1pt}
- Sets the footer line thickness to 1pt.
Open an example of the fancyhdr package in Overleaf
Reference guide
The following commands can be used in the headers and footers to add custom information
- adds number of the current page.
\thepage
- adds number of the current chapter.
\thechapter
- adds number of the current section.
\thesection
- adds the word "Chapter" in English or its equivalent in the current language.
\chaptername
- adds name and number of the current top-level structure (for example, Chapter for reports and books classes; Section for articles ) in uppercase letters.
\leftmark
- adds name and number of the current next to top-level structure (Section for reports and books; Subsection for articles) in uppercase letters.
\rightmark
Further reading
For more information see:
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Debugging Compilation timeout errors
- How-to guides
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Fractions and Binomials
- Aligning Equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management in LaTeX
- Bibliography management with biblatex
- Biblatex bibliography styles
- Biblatex citation styles
- Bibliography management with natbib
- Natbib bibliography styles
- Natbib citation styles
- Bibliography management with bibtex
- Bibtex bibliography styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections and equations
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typing exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class
- Tips