4

I've seen some books that have the page number in the middle of the page, in the margin note; i think it make it easier to look for a particular (IMHO). Is there any chance to do this in LaTeX?

1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – Herr K.
    Dec 9, 2013 at 2:51

2 Answers 2

4

The backgound package can achieve this.

All page numbers on right margin

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\pagestyle{empty}

\usepackage{background}
\backgroundsetup{
  color=black,angle=0,opacity=1,scale=1,
  position=current page.east,anchor=left,
  contents={\tikz\node[fill=gray!50,align=center,text width=5ex]{\thepage};}
}


\begin{document}
%\setcounter{page}{100} % uncomment to see effect of large page number
\lipsum[1-20]

\end{document}

Output

enter image description here


Page numbers on different of sides

If you want page numbers to be placed at different sides for odd and even pages, then you can enlist the help of changepage package:

Code

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\pagestyle{empty}
\usepackage[strict]{changepage}
\usepackage{background}

\newcommand\pnum{
  \begin{tikzpicture}[remember picture,overlay]
    \checkoddpage
    \ifoddpage
      \node[fill=gray!50,align=center,text width=5ex,anchor=west]at(current page.west){\thepage};
    \else
      \node[fill=gray!50,align=center,text width=5ex,anchor=east]at(current page.east){\thepage};
    \fi
  \end{tikzpicture}
}

\backgroundsetup{color=black,angle=0,opacity=1,scale=1,contents={\pnum}}


\begin{document}
%\setcounter{page}{100} % uncomment to see effect of large page number
\lipsum[1-20]

\end{document}
2
  • 2
    Since background will load tikz automatically, I think there is no need to load the package tikz manually. :)
    – Ch'en Meng
    Dec 9, 2013 at 6:59
  • @Ch'enMeng: Thanks :) It was there because I didn't use background initially. Doesn't hurt to leave it there anyways, as long as OP sees your comment ;)
    – Herr K.
    Dec 9, 2013 at 7:12
3

With eso-pic

\documentclass[a4paper,twoside]{article}
\usepackage{eso-pic}
\usepackage{xcolor}
\usepackage{blindtext} % just for the example
\usepackage{ifoddpage}

\AddToShipoutPicture{%
  \AtTextCenter{%    
    \checkoddpage
     \ifoddpage
       \put(\LenToUnit{\dimexpr.5\paperwidth-5mm\relax},0){\colorbox{gray}{\makebox[10mm][c]{\thepage}}}%
     \else
       \put(\LenToUnit{\dimexpr-.5\paperwidth-5mm\relax},0){\colorbox{gray}{\makebox[10mm][c]{\thepage}}}%
     \fi
}}
\pagestyle{empty}
\begin{document}

\blinddocument % just for the example
\clearpage
\setcounter{page}{1000}
\blinddocument
\end{document}

enter image description here

You must log in to answer this question.

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