# How do you Right-Justify Page Numbers and get them in the header?

When I made PDFs with Texmaker the page numbers are by default at the bottom of the page (i.e. in the footer) and are centred. How do I change this?

-
the fancyhdr package can arrange this for you. someone may even tell you how, if you provide a minimal example that can be patched for instructional purposes. – wasteofspace Feb 21 '13 at 9:41
see tex.stackexchange.com/questions/20109/… as well – macmadness86 Feb 24 '13 at 2:09

## 2 Answers

depending on the document class you're using, you might not even need fancyhdr (Which is why a minimal example would be useful, so we know ›where‹ you are). For example, the komascript bundle comes with the scrpage2 package, which, however, also works with other classes as well. Here's what I use, except I put them in the footer rather than the header:

\documentclass[12pt]{scrartcl} % or article, etc.
\usepackage{scrpage2}
\usepackage{blindtext}
\pagestyle{scrheadings}
\clearscrheadfoot %clears headers + footers
\ohead{\thepage\hspace*{3em}} %sets new header
\begin{document}
\Blindtext\Blindtext\Blindtext
\end{document}


See also »adapting page headers and footers« in scrguien.pdf

-

as mentioned, you could use the fancyhdr package. It is more complicated, but I use it for everything anyway, because it is so robust. A couple things to note:

1. I use xelatex
2. I use fancyhdr in conjunction with geometry (notice the options includefoot and includehead: These keep the header and footer within margins, but if you check out the geometry package, you can find all kinds of settings.

The main thing you want to look at is \rhead{\thepage}

\thepage is the page number variable (counter)

Here is an example:

\documentclass[12pt]{article}
\usepackage{fontspec}
%SET MARGINS (AND PAGE DIMENSIONS)
\usepackage[includefoot,includehead,top=2.5cm,bottom=2.5cm,left=2.5cm,right=2.5cm]{geometry}
%HEADER FOOTER
\usepackage{fancyhdr}
\lhead{} \chead{} \rhead{\thepage} %sets header left center right
\lfoot{} \cfoot{} \rfoot{} %sets footer left center right
\renewcommand{\headrulewidth}{0.0pt} %optional horizontal rule thickness
\renewcommand{\footrulewidth}{0.0pt} %optional horizontal rule thickness
\pagestyle{fancy}%ADD HEADER FOOTER TO PAGE EXCEPT TITLE PAGE %ensure fancyhdr is applied to doc
%USE \thispagestyle{EMPTY} BELOW MAKETITLE IF YOU USE IT OR \thispagestyle{FANCY}

\begin{document}
Test Document
\end{document}


Another thing to note. If you are using the article class and you use a \maketitle command, by default, the first page will not have the header/footer from fancyhdr, but will have the default page number. To deal with this, use

• \thispagestyle{empty} % disable header/footer
• \thispagestyle{fancy} % apply fancyhdr header/footer

Let us assume you want the title page to have no header/footer. You will run into another problem, namely that the page number counter still starts with the title page, but you want page 1 to be the first page with content. To solve this, just put a

• \setcounter{page}{1} % sets the counter to value

on whichever page you want to be page 1.

-