0

Some questions and answers exist on how to place the page numbers (I quote) "in the bottom (right) corner", but different people seem to have different (and multiple) definitions of such corners.

I am looking to place the page number, in the extreme bottom right corner, understood as: as far to the right and as far to the bottom as possible (still perfectly visible).

That's just a little bit of a funny exercise, but of course I will not want the page numbers all the way there, for serious purposes.

For serious purposes, I am looking for an answer on how to place the page numbers in an arbitrary position (or applied, almost in the extreme right bottom corner). This will need to answer 2 components:

  • How to shift the vertical component: this seems easy (in purposes known to me) using \geometry{footskip=...pt}.
  • How to shift the horizontal component: this can be (somewhat) done with \usepackage{geometry} & \hoffset=50pt... BUT NOT QUITE -> It also shifts all of the contents on the page to the right. In particular, I am looking for a fix for this problem (unless you studious people would know a solution where you would like to avoid using \hoffset of course).

Here is a Minimal Working (rather: not-working) Example:

MnotWE

\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\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}
\pagestyle{fancy}

\hoffset=50pt
\geometry{footskip=50pt}

\begin{document}
\lipsum
\end{document}

See how EVERYTHING is shifted 50pt to the right? Not ideally!

2 Answers 2

3

Here is a suggestion using package scrlayer-scrpage instead fancyhdr. Than you can define a new layer and add this new layer to an existing page style.

\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{lipsum} % only for showing some sample text

\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles% clear all headers and footers
\DeclareNewLayer[
  foreground,
  align=br,
  hoffset=\paperwidth,
  voffset=\paperheight+\dp\strutbox,
  contents={\vfill\hfill\pagemark}
]{pagenumberbottomright}

\AddLayersToPageStyle{scrheadings}{pagenumberbottomright}
\begin{document}
\lipsum\lipsum
\end{document}

enter image description here

If would be also possible to load only scrlayer and define a new layer page style.

\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{lipsum} % only for showing some sample text

\usepackage{scrlayer}
\DeclareNewLayer[
  foreground,
  align=br,
  hoffset=\paperwidth,
  voffset=\paperheight+\dp\strutbox,
  contents={\vfill\hfill\pagemark}
]{pagenumberbottomright}
\DeclareNewPageStyleByLayers{pnbr}{pagenumberbottomright}
\pagestyle{pnbr}

\begin{document}
\lipsum\lipsum
\end{document}

The result is the same as above.


Update

You can add a layer to different page styles. If the page number should be also on pages with style plain that is used by chapter and part pages you can use

\documentclass{report}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{blindtext} % only for showing some sample text

\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles% clear all headers and footers
\DeclareNewLayer[
  foreground,
  align=br,
  hoffset=\paperwidth,
  voffset=\paperheight+\dp\strutbox,
  contents={\vfill\hfill\pagemark}
]{pagenumberbottomright}

\AddLayersToPageStyle{scrheadings}{pagenumberbottomright}
\AddLayersToPageStyle{plain}{pagenumberbottomright}

\begin{document}
\part{A part}
\blinddocument
\end{document}

If the page number should be on really every page including pages using page style empty than add the layer to page style @everystyle@.

\documentclass{report}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{blindtext} % only for showing some sample text

\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles% clear all headers and footers
\DeclareNewLayer[
  foreground,
  align=br,
  hoffset=\paperwidth,
  voffset=\paperheight+\dp\strutbox,
  contents={\vfill\hfill\pagemark}
]{pagenumberbottomright}

\AddLayersToPageStyle{@everystyle@}{pagenumberbottomright}

\begin{document}
\part{A part}
\blinddocument
\clearpage
\pagestyle{empty}
\Blindtext
\end{document}

Note that if you only load scrlayer (instead scrlayer-scrpage) you have to declare plain as a layer page style.

\documentclass{report}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{blindtext} % only for showing some sample text

\usepackage{scrlayer}
\DeclareNewLayer[
  foreground,
  align=br,
  hoffset=\paperwidth,
  voffset=\paperheight+\dp\strutbox,
  contents={\vfill\hfill\pagemark}
]{pagenumberbottomright}
\DeclareNewPageStyleByLayers{pnbr}{pagenumberbottomright}
\DeclarePageStyleByLayers{plain}{pagenumberbottomright}
\pagestyle{pnbr}

%\AddLayersToPageStyle{@everystyle@}{pagenumberbottomright}

\begin{document}
\part{A part}
\blinddocument
\clearpage
\pagestyle{empty}
\Blindtext
\end{document}
2
  • How to make it work on all pages (including pages where \part{...}s or \chapter{...}s start, while in \documentclass{report} please?
    – O0123
    Commented Apr 22, 2016 at 2:30
  • 1
    @VincentVerheyen See my updated answer.
    – esdd
    Commented Apr 22, 2016 at 6:51
1

TikZ package can be used to place page numbers at arbitrary positions. You will also need the background package to set a new background. Her is an example:

\documentclass[a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz,background}
\usepackage{fancyhdr}
\usepackage{lipsum} % only for showing some sample text

\fancyhf{} % clear all header and footers
\renewcommand{\headrulewidth}{0pt} % remove the header rule
\pagestyle{fancy}

\backgroundsetup{%
contents={%
  \begin{tikzpicture}[overlay,opacity=100]
    \node[text=black] at ([shift={(-1em,1em)}]current page.south east){\thepage};
  \end{tikzpicture}
  },
  scale=1,
  angle=0
}

\begin{document}
\lipsum[1-10]
\end{document}

Which gives this:

enter image description here

1
  • I can not retrieve any visible footnote upon compilation. It's probably a small glitch, would you know what's causing the issue?
    – O0123
    Commented Apr 22, 2016 at 0:14

You must log in to answer this question.

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