# 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

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}
\begin{document}
\Blindtext\Blindtext\Blindtext
\end{document}


-

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{fancyhdr}
\lfoot{} \cfoot{} \rfoot{} %sets footer left center right
\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