Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
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

2 Answers 2

up vote 3 down vote accepted

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.

share|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{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\usepackage{lastpage} % enables \pageref{LastPage}
\ihead{}
\chead{}
\ohead{}
\ifoot{}
\cfoot{\pagemark of \pageref*{LastPage}}
\ofoot{}

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}.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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