# Page number in the margin note

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?

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

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}


# 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}

• Since background will load tikz automatically, I think there is no need to load the package tikz manually. :) – Ch'en Meng Dec 9 '13 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 '13 at 7:12

With eso-pic

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

\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}