[Tex/LaTex] How to get no header but still get “page x of y” in footer

fancyhdrheader-footerlastpagepage-numbering

I'd like to get "page x of y" in a footer on each page, and the way I've found is to use:

\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}
\cfoot{Page \thepage\ of \pageref{LastPage}}

This works but has introduced a solid line at the top of each page and some headers. How do I get "page x of y" without any headers at all?

Best Answer

Regarding the header settings when using fancyhdr: In order to remove the header rule, you need to set it to 0pt using

\renewcommand{\headrulewidth}{0pt}

Although this is a length, it's used as a command within the header. In order to clear the entire header, use

\fancyhead{}

which clears everything (left, centre and right, on odd and even pages).

If you want the mean \chapter page (I assume you are using a document class like book or report), you can set the page style for that specific chapter manually using

\thispagestyle{fancy}

The reason for this is because \chapter (and \chapter*) sets the page style to plain by default (since the page configuration is different from other pages, with a large open "header"). Here is a minimal example capturing the above:

enter image description here

\documentclass{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\usepackage{lastpage}% http://ctan.org/pkg/lastpage
\pagestyle{fancy}% Set default page style to fancy
\renewcommand{\headrulewidth}{0pt}% Remove header rule
\fancyhead{}% Remove all header contents
\cfoot{Page \thepage\ of \pageref{LastPage}}% Page X of Y in the footer (centered)
\begin{document}
\chapter{A chapter}
\thispagestyle{fancy}% Revert 'plain' page style (from \chapter) to fancy
\lipsum[1-25]% dummy text
\end{document}‚Äč

If you want the page style to be fancy regardless (or globally), and therefore would like to avoid setting to fancy manually at every \chapter, you could just overwrite the plain page style with fancy (or create a new plain page style altogether; it depends on your usage/preference):

\makeatletter
\let\ps@plain\ps@fancy% Let 'plain' be exactly the same as 'fancy'
\makeatother

Add the above after setting all the fancy header styles, or see section 7 Redefining plain style (p 7) of the fancyhdr documentation. Note, the lipsum package is not necessary; it was merely used for creating dummy text, Lorem Ipsum style.

Related Question