Headers and Footers, Page Numbering
fancyhdr package
fancyhdr packagefancyhdr is a package that provide extensive control of page headers and footers in LATEX.
Here is a diagram presenting the general structure of headers and footers defined by fancyhdr for a two-sided document:

It appears that:
headers and footers can contain different content on left (even) and right (odd) pages.
headers and footers are structured into 3 different zones:
Left
Right
Center
The rule that seperating the main document and the header/footer is optional.
Coordinates in fancyhdr
fancyhdrCommands provided by fancyhdr use single-letter abbreviations, called “coordinates”, to identify specific header and footer zones and page locations:
O/E - specify Odd/Even pages (this is only applicable when it comes to 2-sided documents)
H/F - indicate Header/Footer
L, C or R: for the Left, Centre and Right “zone” of the header or footer
Therefore, when specify location (coordinates), you may see the combination of these abbreviations, for example: LE, RO.
Commands in fancyhdr
fancyhdrTo define the content of headers and footers, we can use:
\fancyfoot[location]{content}\fancyhead[location]{content}\fancyhf[location]{content}
Note that, \fancyfoot and \fancyhead are just \fancyhf with F and H in the location part, respectively.
As a result, in some condition, \fancyhf can get a total of 3 coordinates and \fancyfoot and \fancyhead can get 2.
Let's take a look at an example:
We instantiate the package by
\usepackage{fancyhdr}and allow headers and footers in our document by\pagestyle{fancy}.\fancyhead{}- clears the settings for the headers\fancyhead[C]{\textbf{Report on the performance of retail stores}}- Create a header in the center location\fancyfoot{}- clears the settings for the footers\fancyfoot[L]{From: MisterA}- Create a footer in the left position\fancyhf[CF]{\thepage}- Create a page number, positioning in the center of the footer
Configure fancyhdr's rulers
fancyhdr's rulersHere are some rule-related commands provided by fancyhdr:
\headrulewidth
define the thickness of a line under the header (default = 0.4pt)
\footrulewidth
define the thickness of a line above the footer (default = 0pt, that is the reason why there's no footer rule by default)
\headruleskip
define the distance between the line and the header text (only available since version 4.0)
\footruleskip
define the distance between the line and the footer text
\headrule
macro to completely redefine header rules (lines)
\footrule
macro to completely redefine footer rules (lines)
\headwidth
a length parameter that defines the total width of the headers and footers
Since these are macro (commands), we must use \renewcommand to modify their values instead of \setlength.
Page Numbering
As we mentioned in Commands in fancyhdr, we can quickly typeset the page number by using \thepage in our headers or footers.
However, in case you want to change their appearance (normal number, Roman numeral or letters), you can use this command in your preamble: \pagenumbering{style}.
Applicable style value:
arabic: use Arabic numerals (1, 2, 3, ...)alph: use lowercase letters (a, b, c, ...)Alph: use uppercase letters (A, B, C, ...)roman: use lowercase roman numerals (i, ii, iii, ...)Roman: use uppercase roman numerals (I, II, III, ...)
\pagenumbering does not only affects page number in the headers/footers, but also the number in the table of contents!
Special case of Page numbering: page X of N
In this case, we need to use lastpage package with this command:
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}
For reference:
https://www.overleaf.com/learn/latex/Headers_and_footers - this also has some useful guides on making "book" document
Last updated