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


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

\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


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


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


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

\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)
\chapter{A chapter}
\thispagestyle{fancy}% Revert 'plain' page style (from \chapter) to fancy
\lipsum[1-25]% dummy text

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):

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

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