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?

  • 3
    Add \renewcommand{\headrulewidth}{0pt} to your document preamble. This should remove the header rule. – Werner Jan 5 '12 at 19:32
  • I've also flagged both of your "answers", which should be edits to the original question. BTW, welcome at tex.sx! – lockstep Jan 5 '12 at 19:54

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.

| improve this answer | |
  • Thanks Werner! That works fine. One more thing - how can I get "page x of y" on the first page as well as all the other pages? Thanks again. Harry – Harry Macpherson Jan 5 '12 at 19:37
  • Oops - actually it doesn't work fine. It removes the solid lines at the top of every page, but I'm still getting words in headers in the second part of the document. I'd like to get no headers at all on any page. – Harry Macpherson Jan 5 '12 at 19:39

I think scrpage2 is quite a nice package do do things like these. The following creates what you want, plus it leaves a lot of options open.

\usepackage{lastpage} % enables \pageref{LastPage}
\cfoot{\pagemark of \pageref*{LastPage}}

For example, you can easily add the current chapter to the top of the page by using \automark[subsection]{section} and then e.g. \ihead{\headmark}.

| improve this answer | |
  • In addtion we have nccfancyhdr and titleps. – Javier Bezos Jan 7 '12 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.