27

I want to change the position of the page number.

I've read around here that some people suggest using the fancyhdr package, but I don't want to use it – I'm a beginner to LaTeX so I don't want to use a package that could change the margins and other specifications to the layout that I've already made. Does anyone know how to move the page number?

Please correct me if my concerns about fancyhdr are unfounded.

5
  • What documentclass do you use? And what pagestyle? And where do you want to move the pagenumber to? Jan 12, 2011 at 21:06
  • fancyhdr didn't change any margin ... However, what documentclass you are using?
    – user2478
    Jan 12, 2011 at 21:08
  • Here's my code: pastebin.com/raw.php?i=DGVEJvzX.
    – Miriam
    Jan 12, 2011 at 21:13
  • You'll see that I used \thispagestyle{empty} \pagestyle{empty} just so that I could remove the page number until I found a way to move it...
    – Miriam
    Jan 12, 2011 at 21:18
  • 2
    @Harald Hanche-Olsen -- I want to move the page number to the bottom right or left hand corner of the page.
    – Miriam
    Jan 12, 2011 at 21:20

3 Answers 3

39

As a beginner you should be using packages, and making use of them as much as possible. Generally speaking, packages don't mess up things that they are not designed to change, so you shouldn't be worrying much about using them, especially if they are the kinds of packages that are recommended often by users here. Unless you are using a special documentclass such as memoir or one of the KOMA classes, you should be using fancyhdr, because it provides a very simple interface to do exactly what you want.

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lipsum} % only for showing some sample text
\fancyhf{} % clear all header and footers
\renewcommand{\headrulewidth}{0pt} % remove the header rule
\rfoot{\thepage}
%
%lfoot{\thepage} % puts it on the left side instead
%
% or if your document is 2 sided, and you want even and odd placement of the number
%\fancyfoot[LE,RO]{\thepage} % Left side on Even pages; Right side on Odd pages
%
\pagestyle{fancy}
\begin{document}
\lipsum
\end{document}

The best reason to use a package is that package writers are generally much more experienced in doing things than the average end user, and so a package will deal with problems that might not even occur to you (even when you become more experienced with LaTeX); also, there's really no sense in re-inventing the wheel, when good tools with long track records of use are available.

See also this page on the Wiki for some recommendations of useful packages. Since you also mentioned changing margins, you should also probably be using the geometry package instead of doing that by hand, too.

6
  • 2
    Thanks for the explanation! I guess I was under the impression that if there were conflicting environments (namely if the package had different arguments than the ones I had), then my document would look messed up. I will try using fancyhdr and what you recommended above to resolve my issue. Also, if you saw the my earlier comments to Herbert and Harald, I am using a geometry package for margins. Actually, I posted my code in one of the above comments.
    – Miriam
    Jan 12, 2011 at 22:11
  • @Halime However, you should look at the console output if you use fancyhdr to set headers because it will tell you if the headers take more space than is available, and will specify the minimum height required if they do. You then feed that information to geometry to avoid unexpected changes to your page layout. But this is a good thing because it is a change you need to make if you are using headers which are too big for the available space!
    – cfr
    Dec 19, 2014 at 23:07
  • "As a beginner you should be using packages, and as much as possible." this might be confusing, since we tell people not to use that much packages. Rule of thumb should be to load/use the package one actually needs. Having a 5000 line preamble loading almost every package on CTAN seems counterintuitive.
    – Johannes_B
    Aug 12, 2017 at 13:12
  • @Johannes_B I think this is a bit of English confusion. "and as much as possible" here means that you should use them as much as possible not you should use as many as possible. But I can change the wording to make it clearer.
    – Alan Munn
    Aug 12, 2017 at 13:33
  • Oh yes, confusion on my part. Now that you made it clear, i was confusing much and many. But as far as i heard, native english speakers sometimes confuse that as well (would like to know if this is true) and we have many non-native speakers around. I think a little clarification would be nice.
    – Johannes_B
    Aug 12, 2017 at 13:36
14
\documentclass[twoside]{article}

\makeatletter
\def\ps@myPS{%
    \def\@oddfoot{\null\hfill\thepage}
    \def\@evenfoot{\thepage}%
    \def\@evenhead{\null\hfil\slshape\leftmark}%
    \def\@oddhead{{\slshape\rightmark}}}%
\makeatother

\pagestyle{myPS}

\begin{document}

foo
\clearpage
blah
\end{document}
4
  • Thank you! I will try that (as well as Alan Munn's response) to see if that will work for me.
    – Miriam
    Jan 12, 2011 at 22:13
  • @Herbert, I managed to move the page number to the right side of footer by controlling rofoot and refoot in koma-script packages. However, I have a problem of accurately specifying the distance between the page number and margins. So, I would be grateful if you could consider my question tex.stackexchange.com/q/322024/2288
    – Diaa
    Aug 2, 2016 at 17:33
  • see my answer to your question
    – user2478
    Aug 2, 2016 at 17:46
  • This worked much better than fancyhdr for me because my document has multiple page sizes. Thank you! Apr 30, 2020 at 0:07
1

I absolutely agree with Alan Munn with one limitation: His answer might give the impression that the fancyhdr package is without alternative. However, there are some other packages to configure the page header and page footer.

Here I've adapted his example for using package scrlayer-scrpage instead of fancyhdr:

\documentclass{article}
\usepackage{scrlayer-scrpage}
\usepackage{lipsum} % only for showing some sample text
\clearpairofpagestyles% remove all default elements from page styles scrheadings
                      % and plain.scrheadings
\ofoot*{\pagemark}% add pagination to the outer part of the page footer
\begin{document}
\lipsum
\end{document}

pagination on the right side of the footer using scrlayer-scrpage

Using scrlayer-scrpage would also be recommended using a KOMA-Script class like scrartcl instead of a standard class:

\documentclass{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage{lipsum} % only for showing some sample text
\cfoot*{}% remove the default center pagination from the footer
\ofoot*{\pagemark}% add pagination to the outer part of the page footer
\begin{document}
\lipsum
\end{document}

I've used here another solution to remove the default pagination in the middle of the footer. You can find more examples for using scrlayer-scrpage in the manual and in the KOMA-Script wiki (also available in German).

For such a simple page style with pagination only, you could also use package scrlayer:

\documentclass{article}
\usepackage{scrlayer}
\usepackage{lipsum} % only for showing some sample text
\DeclareNewLayer[% declare a new layer
  foreground,% printed in the foreground
  foot,% placed to the page footer
  contents={\hfill\thepage}% with right aligned page number as content
]{pagenumber}
\RedeclarePageStyleByLayers{plain}{pagenumber}% redefine page style plain to use the newly defined layer
\pagestyle{plain}% (re)activate the (re)defined page style
\begin{document}
\lipsum
\end{document}

As you can see, package scrlayer is more low-level than scrlayer-scrpage. Package scrlayer-scrpage adds an extra user level to package scrlayer.

Here I've adapted his example for using package titleps instead of fancyhdr:

\documentclass{article}
\usepackage{titleps}
\usepackage{lipsum} % only for showing some sample text
\newpagestyle{pagenumberfooterright}{% defining a new page style
  \setfoot{}{}{\thepage}% with page number at the right side
}
\pagestyle{pagenumberfooterright}
\begin{document}
\lipsum
\end{document}

page number at the right side of the footer with titleps

See the manuals of the packages for more information.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .