[Tex/LaTex] How to display page numbering on top of the page

header-footerpage-numbering

I've been searching for quite some time now, but I can't seem to find an answer to my problem. This is how my page numbering commands are:

\renewcommand{\thepage}{\arabic{page}}
\setcounter{page}{1}

Now, the page numbers are showing up at the bottom of the page. I want them, however, to be on top of the page, in the header. Is there any way I can get this done? Thanks!

EDIT: I'm using the documentclass article and packages as seen below.

\documentclass{article}
\usepackage[a4paper,margin=3cm]{geometry}
\author{Mike}

\usepackage{pdfpages}
\usepackage[dutch]{babel}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[parfill]{parskip}
\usepackage[hang,bf,small]{caption}
\usepackage{booktabs}

Best Answer

You can load fancyhdr. Commands for single sided documents were usually, for example (right head, left head, right foot, and so on):

\pagestyle{fancy}
\fancyhf{}
\rhead{}
\lhead{}
\rfoot{}

Although apparently the last three showed here are now obsolete.

There are other styles besides fancy which is used here, like plain, but you can make up your own style. \fancyhf{} empties the head and foot so you can fill them with whatever you want.

The new syntax has the following commands:

\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{}
\fancyhead[LO,RE]{}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{}
\setlength{\headheight}{15pt}

\fancyhead is for the header, \fancyfoot is for the footer, pretty simple. The various letters are: L for the left side of the page, R for the right side, C for center, E for even pages and O for odd pages.

You can also add these commands for the lines:

\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}

You can enter whatever you want in the fields above, but you have some variables at your disposal so that nothing is hard-coded:

  • \thepage
    Page number.

  • \thechapter
    Number of current chapter.

  • \thesection
    Number of current section

  • \chaptername
    Adds the word "chapter" or the corresponding word if the document is in a different language.

  • \leftmark and \rightmark These add the top level and next-to-top level structure number and name (though it can be modified) for the current document class. For example, in article it would be section and subsection.