I am trying to use @Gonzalo-Medina code (Show current chapter number on each page margin) to display chapter number on each pages from a book document class. I used a counter to overcome the issue with appendix chapters. Unfortunately, I still have issues with my code : The boxes are two big and not displayed correctly, or the last chapter of the main part of the document is not displayed correctt (no number).
The question is how to set the code properly to work with appendices and that could display all chapters.
Here is my MWE that does not fit with appendices
\PassOptionsToPackage{x11names}{xcolor}
\documentclass[]{book}
\usepackage[contents={},opacity=1,scale=1,color=white]{background}
\usepackage[a4paper]{geometry}% just for the example
\usepackage{tikzpagenodes}
\usepackage{totcount}
\usepackage{lipsum}% just to generate text for the example
\usepackage{fancyhdr}
\usepackage{shorttoc}
\usetikzlibrary{calc}
\newif\ifMaterial
\newlength\LabelSize
\setlength\LabelSize{3.5cm}
% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}
\AtBeginDocument{%
\regtotcounter{chapter}
\setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax}
\ifdim\LabelSize>3.5cm\relax
\global\setlength\LabelSize{3.5cm}
\fi
}
\newcommand\AddLabels{%
\Materialtrue%
\AddEverypageHook{%
\ifMaterial%
\ifodd\value{page} %
\backgroundsetup{
angle=90,
position={current page.east|-current page text area.north east},
vshift=12pt,
%hshift=-\thechapter*\LabelSize,
hshift=-\thechapshift*\LabelSize,
contents={%
\tikz\node[fill=DodgerBlue4,anchor=west,text width=\LabelSize,
align=center,text height=15pt,text depth=13pt,font=\large\sffamily] {\thechapter};
}%
}
\else
\backgroundsetup{
angle=90,
position={current page.west|-current page text area.north west},
vshift=-12pt,
hshift=-\thechapshift*\LabelSize,
%hshift=-\thechapter*\LabelSize,
contents={%
\tikz\node[fill=DodgerBlue4,anchor=west,text width=\LabelSize,
align=center,text height=15pt,text depth=13pt,font=\large\sffamily] {\rotatebox{180}{\thechapter}};
}%
}
\fi
\BgMaterial%
\else\relax\fi}%
\addtocounter{chapshift}{1}%
}
\newcommand\RemoveLabels{\Materialfalse}
\begin{document}
\shorttoc{Sommaire}{0}\pagestyle{fancyplain}
\chapter{Test Chapter One}
\AddLabels
\lipsum[1-2]
\chapter{Test Chapter Two}
\lipsum[1-12]
\appendix
%\RemoveLabels
\chapter{Annexe A}
\lipsum[1-2]
\tableofcontents
\RemoveLabels
\end{document}
the part I am trying to change to make this work with appendices are :
hshift=-\thechapshift*\LabelSize,
%hshift=-\thechapter*\LabelSize,
maybe that's not a good way to try... Is this possible? If so, how can I implement it?
