6

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}
2
12

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.

4
  • That is odd. My processor does not return those errors. I am using Miktex. Is there a way to add space between the section header and page number? Setting the \headheight to at least 15 only affects the header size whereas I want to move only the page number up and to the right without moving the section heading. – Marcin Wiezel Apr 25 '13 at 23:07
  • @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. – Gonzalo Medina Apr 25 '13 at 23:12
  • 1
    @MarcinWiezel please see my updated answer; I incorporated suggestions to move the number up and to the right. – Gonzalo Medina Apr 25 '13 at 23:19
  • that did the trick. – Marcin Wiezel Apr 26 '13 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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