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:
The first one, tells you that, unless you activate the
twoside
class option,E
(for Even) won't have any effect (similar remark applies toO
). I added the option in my example code below (if you don't want that option, delete it and removeE
andO
from yourfancyhdr
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
Your code, after incorporating the changes:
I added the
showframe
option togeometry
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
andgraphicx
, 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 loadinggeometry
, you can use itsheadsep
key:To move the page number to the right, you can use
\fancyheadoffset
, as inOf course, instead of
1cm
, use the lengths that best suit your needs.