25

I want to change the position of the page number. I've read around here that some suggest to use 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 have any idea how to, or possibly correct me if my concerns (in regard to fancyhdr) are unfounded?

  • What documentclass do you use? And what pagestyle? And where do you want to move the pagenumber to? – Harald Hanche-Olsen Jan 12 '11 at 21:06
  • fancyhdr didn't change any margin ... However, what documentclass you are using? – user2478 Jan 12 '11 at 21:08
  • Here's my code: pastebin.com/raw.php?i=DGVEJvzX. – Miriam Jan 12 '11 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 '11 at 21:18
  • 1
    @Harald Hanche-Olsen -- I want to move the page number to the bottom right or left hand corner of the page. – Miriam Jan 12 '11 at 21:20
35

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.

  • 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 '11 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 '14 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 '17 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 '17 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 '17 at 13:36
12
\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}
  • Thank you! I will try that (as well as Alan Munn's response) to see if that will work for me. – Miriam Jan 12 '11 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 '16 at 17:33
  • see my answer to your question – user2478 Aug 2 '16 at 17:46

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.