0

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}
  • 2
    Usual packages to deal with that: fancyhdr, scrlayer-scrpage and titleps. Same information can be found when hovering over the tag {header-footer} on the left of your name. – Johannes_B Mar 28 '16 at 9:31
  • 1
    It's important to know what document class you're using. – egreg Mar 28 '16 at 9:59
  • I added some more information to my post. – Mike Mar 28 '16 at 11:39
3

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.

  • The \rhead, \lhead and \cfoot commands are obsolete; \fancyhead and \fancyfoot should be used everywhere, with the suitable optional argument, that can consist of a single letter R, C or L. – egreg Mar 28 '16 at 12:24
  • @egreg Oh, they still appear in the manual though. – Alenanno Mar 28 '16 at 12:38
  • It's unfortunate that the author didn't really update the manual after introducing the new syntax. The new syntax avoids much of the clumsy code needed with the old one. – egreg Mar 28 '16 at 12:39
  • @egreg I'll re-word the answer then. – Alenanno Mar 28 '16 at 12:41
  • @cfr That was badly worded. I meant "left on the page". Thanks for noticing, I'll fix it. – Alenanno Mar 28 '16 at 14:31
3

You don't need to renew \thepage. Arabic page numbering is default for article.cls.

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[rh]{\thepage}% right header
%\fancyhf[lh]{}% left header
%\fancyhf[ch]{}% centre header
\renewcommand\headrulewidth{0pt}% remove if you want a rule beneath the header
%\fancyhf[lf]{}% left footer
%\fancyhf[cf]{}% centre
%\fancyhf[rf]{}% right

For example:

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[rh]{\thepage}% right header
%\fancyhf[lh]{}% left header
%\fancyhf[ch]{}% centre header
\renewcommand\headrulewidth{0pt}% remove if you want a rule beneath the header
%\fancyhf[lf]{}% left footer
%\fancyhf[cf]{}% centre
%\fancyhf[rf]{}% right
\usepackage{kantlipsum}
\begin{document}
\kant[1]
\end{document}

right header page number

  • @egreg Not really sure what to say about that, to be honest. I really don't know what you're trying to tell me. – cfr Mar 28 '16 at 14:00
  • Oh, yes, it's an argument to \fancyhf! However I'd prefer \fancyheader[R]{\thepage}, which is clearer. – egreg Mar 28 '16 at 14:08
  • @egreg I find \fancyhf clearer but no doubt it is a question of what you're familiar with. Just because rh then means 'right header' whereas R just means 'right` and you have to look at the command to know right what. But, as I say, no doubt it is a question of familiarity more than anything. I always use this syntax so I'm used to reading it this way. If you always use the other, I'm sure that seems more natural. – cfr Mar 28 '16 at 14:10

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.