# geometry, fancyhdr: \fancyfoot[C]{\thepage} is not really centered

After switching from the report class to the book class and starting to use the fancyhdr package to control headers/footers, the page numbers in my footers are no longer centered.

This is my fancyhdr setup:

\usepackage{fancyhdr}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center
\renewcommand{\footrulewidth}{0pt}}
%activate the style:
\pagestyle{plain}

\usepackage{geometry}
\geometry{a4paper} %paper format
\geometry{left=27.5mm,right=27.5mm,bottom=27.5mm,top=27.5mm} %margins

With this the page numbers are placed off-center. On even pages they are to the right of the center and on odd ones they are to the left of it. What I want is a perfectly centered (with respect to the page) pagenumber in the footer of even and odd pages alike (like it was when I used the report class and no fancyhdrs).

-
The setup for fancyhdr is not sufficient to make a diagnosis; are you also changing the parameters for page building? –  egreg Nov 6 '11 at 20:56
I'm not sure which parameters you mean? –  Matthias Nov 6 '11 at 20:57
If I use that code, the page number goes at the desired place. Do you have some setting to \textwidth or \evensidemargin? –  egreg Nov 6 '11 at 20:59
It's centered in relation to the text, not to the page. You may notice it in twosided layout, when inner and outer margins are different. I suggest keeping centering to the text body, just imagine a full page and the page number below. –  Stefan Kottwitz Nov 6 '11 at 21:01
It's not centered to the page, nor the text here. I will add my page (paper) setup to the question, maybe this is relevant? –  Matthias Nov 6 '11 at 21:03

The solution is to load geometry before fancyhdr and apply the settings, then configure fancyhdr, not the other way round.

A working example:

\documentclass{book}
\usepackage[english]{babel}
\usepackage{geometry}
\geometry{a4paper} %paper format
\geometry{left=27.5mm,right=27.5mm,bottom=27.5mm,top=27.5mm} %margins
\usepackage{fancyhdr}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center
\renewcommand{\footrulewidth}{0pt}}
%activate the style:
\pagestyle{plain}
\begin{document}
\vspace*{\fill}
\centering\thepage
\end{document}


In this example, if \usepackage{geometry} and the \geometry settings are moved below \pagestyle{plain}, the undesired behavior occurs. I wonder why geometry is not even mentioned in the fancyhdr manual, when I see this dependency.

-
Thanks Stefan! In fact, I had just figured it out myself while assembling a proper MWE. –  Matthias Nov 6 '11 at 21:41
@Matthias: That's the great benefit of MWEs, they're basically like debugging :). Have you considered contacting the author of fancyhdr and asking him if this "conflict" should go into the manual? –  doncherry Jan 14 '12 at 17:49