# Customize page numbering into a fixed float box

In a latex book document, I use different layouts by using the command \newgeometry. My footers and margins (marginparwidth,marginparsep) "move" and if I use a standard page numbering, the page numbering move too and it's not beautiful.

I'd like to use a fixed "float" page numbering box in the bottom corner of all of my pages of my document, without consideration of the \newgeometry settings. I'd like specify a (X,Y) position for this box for all of my document, like that :

To complexify, I'd like that the command \thispagestyle{empty} can be understand too : if the \thispagestyle{empty} is specified into a page, the page numbering box is not displayed.

Here is a suggestion with package scrlayer-scrpage. It uses layers for header and footer. It is possible to define new layers and add them to page styles.

So you can use a two new layers for the page numbers: one for odd pages and one for even pages.

In the following example the center of the baseline is 1cm above the lower page border and 2cm left/right of the outer page margin on odd/even pages.

\documentclass{book}
\usepackage{geometry}
\geometry{top=2cm,bottom=3cm,left=2cm,right=4cm,marginparwidth=2.8cm,marginparsep=1cm}

\usepackage{xcolor}

\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\renewcommand\pagemark{\fcolorbox{black}{yellow!30}{\usekomafont{pagenumber}\thepage}}

\DeclareNewLayer[
oddpage,
background,
page,
mode=picture,
contents=\putLR{\makebox[0pt][c]{\pagemark}}
]{pagenumber.odd}
\DeclareNewLayer[
clone=pagenumber.odd,
evenpage,
hoffset=2cm,
contents=\putLL{\makebox[0pt][c]{\pagemark}}
]{pagenumber.even}

\usepackage{blindtext}
\usepackage{showframe}
\begin{document}
\chapter{A chapter}
\Blindtext[10]
\clearpage
\thispagestyle{empty}
{\Huge A page with empty page style.\par}
\clearpage
\Blindtext
\newgeometry{top=8cm,bottom=5cm,right=6cm,left=5cm,marginparwidth=2cm,marginparsep=3mm}
\Blindtext[10]
\end{document}


• It works perfectly. I had a conflict with fancyhdr package, but I've deleted it and it is ok. – lucif Dec 17 '16 at 16:49