[Tex/LaTex] Placing page numbers with Fancyhdr

fancyhdrheader-footer

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}
\renewcommand*{\headrulewidth}{0pt}
\fancyhf{}
\pagestyle{fancy}
\fancyhead[RO,RE]{\thepage} %RO=right odd, RE=right even 
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

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

stuff here

\end{document}

Best Answer

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}
\renewcommand*{\headrulewidth}{0pt}
\fancyhf{}
\pagestyle{fancy}
\fancyhead[R]{\thepage} %R right on all pages 
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength\headheight{14.5pt}
\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:

enter image description here

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} 
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength\headheight{14.5pt}
\fancyheadoffset[R]{1cm}

Of course, instead of 1cm, use the lengths that best suit your needs.

Related Question