# Placing page numbers with Fancyhdr

I have looked through many of the posts on this website, but I am still having trouble placing my page numbers in latex the way I want it.

Essentially, I want to mimic the way MS Word formats page numbers when placed in the top right hand corner. The code I am using places the page number at roughly the same level as my section heading. By the looks of it, if I could just move the page# up a few points, but have the section title stay where it is, everything would look okay. Any help would be appreciated!

Here is my code:

\documentclass[12pt, a4paper]{article}
\usepackage{fullpage}
\usepackage{setspace}
\usepackage{subfigure}
\usepackage{amsfonts, amsmath, amssymb}
\usepackage{dcolumn, pstricks, multirow}
\usepackage{epsfig, subfigure, subfloat, graphicx, float}
\usepackage{anysize, setspace}
\usepackage{verbatim, rotating}
\usepackage{epsfig,graphicx}
\usepackage[abbr]{harvard}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{hyperref}
\usepackage{epsfig}
\usepackage{epstopdf}
\usepackage{xcolor}
\usepackage{caption}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
\usepackage{titlesec}
\titleformat{\section}[block]
{\normalfont\Large\bfseries\filcenter}{\fbox{\itshape\thesection}}{1em}{}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

\setcounter{page}{34}
\section*{Appendix A: Methodology}

stuff here

\end{document}

• Don't load both fullpage and geometry: they fight each other. Apr 25, 2013 at 22:06
• Please always remove all irrelevant packages before posting a question here! See I've just been asked to write a minimal example, what is that? (irrelevant = problem shows up without the package) Apr 25, 2013 at 23:19

When you process your document, you get three warnings; two of them directly concern your problem:

Package Fancyhdr Warning: \fancyhead's E' option without twoside option is useless on input line 27.

Package Fancyhdr Warning: \headheight is too small (0.0pt): Make it at least 14.49998pt.

The first one, tells you that, unless you activate the twoside class option, E (for Even) won't have any effect (similar remark applies to O). I added the option in my example code below (if you don't want that option, delete it and remove E and O from your fancyhdr definitions). Also, there's no need to use [RE,RO], since this is equivalent to just [R].

The second one, tells you that the default reserves spacing for your header is too small and that you need to increase it using

\setlength\headheight{14.5pt}


Your code, after incorporating the changes:

\documentclass[12pt,twoside,a4paper]{article}
\usepackage{fullpage}
\usepackage{setspace}
\usepackage{subfigure}
\usepackage{amsfonts, amsmath, amssymb}
\usepackage{dcolumn, pstricks, multirow}
\usepackage{epsfig, subfigure, subfloat, graphicx, float}
\usepackage{anysize, setspace}
\usepackage{verbatim, rotating}
\usepackage{epsfig,graphicx}
\usepackage[abbr]{harvard}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{hyperref}
\usepackage{epsfig}
\usepackage{epstopdf}
\usepackage{xcolor}
\usepackage{caption}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
\usepackage{titlesec}
\titleformat{\section}[block]
{\normalfont\Large\bfseries\filcenter}{\fbox{\itshape\thesection}}{1em}{}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\fancyhead[R]{\thepage} %R right on all pages
\renewcommand{\footrulewidth}{0pt}
\begin{document}

\setcounter{page}{34}
\section*{Appendix A: Methodology}

stuff here

\end{document}


I added the showframe option to geometry to have some frames as visual guides:

By the way, do you really need all those packages in your preamble? Notice also that you are loading the same package more than once (avoid this). Also, you load graphics and graphicx, it's enough to load the latter.

If you want to move the header further up, you can increase the headsep length; since you are already loading geometry, you can use its headsep key:

\usepackage[top=1in, bottom=1.5in, left=1in, right=1in,headsep=1cm]{geometry}


To move the page number to the right, you can use \fancyheadoffset, as in

\fancyhead[R]{\thepage}

Of course, instead of 1cm, use the lengths that best suit your needs.
• @MarcinWiezel The messages are not errors, they are warnings (different things; you can see them in the output console and perhaps your editor also has a mechanism for displaying them). The section title doesn't move with the modification of \headheight`; this reserves space for the header. Do you want to move the page number still further up? I wouldn't suggest you moving it to the right (it will fall outside the margins), but if you want to, I'll tell you how tou can achieve it. Apr 25, 2013 at 23:12