# Adding chapter thumbs to an appendix with KOMA-Script

Including an appendix chapter using \include{chapter_appendixA} results in a 'weird error' in overleaf (compiling with XeLaTeX):

! Missing number, treated as zero. p l.1 \chapter{chapter_appendixA} A number should have been here; I inserted 0'.

! Package PGF Math Error: Unknown function A' (in '-A*\LabelSize '). See the PGF Math package documentation for explanation. Type H for immediate help.

The chapter_appendixA.tex file only includes the following:

\chapter{Appendix}
Some text


Other appendix examples do not include a number there. The error arises when activating the gray chapter label boxes using \AddLabels from "Show current chapter number on each page margin" Does anyone have an idea?

My main code is the following:

\documentclass[10pt,twoside,parskip=half,table,xcdraw]{scrbook}
\usepackage[
paperwidth=170mm,
paperheight=240mm,
top=2.5cm,
bottom=3cm,
inner=30mm,
outer=25mm,
heightrounded=true
]{geometry}

\input{preamble.tex}

\raggedbottom

% avoid annoying errors when using Koma-Script with bibtex
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}

\begin{document}

%%%%%%%%%%%%%%%%%%
%% FRONT MATTER %%
%%%%%%%%%%%%%%%%%%

\frontmatter
\tableofcontents

%%%%%%%%%%%%%%%%%
%% MAIN MATTER %%
%%%%%%%%%%%%%%%%%

\mainmatter

\chapter{A chapter}
Some text

%%%%%%%%%%%%%%
%% APPENDIX %%
%%%%%%%%%%%%%%

\appendix
\include{chapter_appendixA}

\end{document}


With accompanyingpreamble.tex:

%%%%%%%%%%%
%% FONTS %%
%%%%%%%%%%%
\usepackage{xcolor}
\usepackage{libertine}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}

%Set chapter titles and numbering
\clearpairofpagestyles

%%%%%%%%%%%%%%%%%%%%%%%
%% chapter numbering %%
%%%%%%%%%%%%%%%%%%%%%%%

%\renewcommand*{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}

% Create header for odd (o) and even (e) pages

\usepackage[times]{quotchap}   % fancy chapter beginning

\pretolerance=10000
\tolerance=10000

% Gray boxes for chapter numbering on pages
\usepackage[contents={},opacity=1,scale=1,color=white]{background}
\usepackage{tikzpagenodes}
\usepackage{totcount}
\usetikzlibrary{calc}

\newif\ifMaterial

\newlength\LabelSize
\setlength\LabelSize{2.5cm}
\AtBeginDocument{%
\regtotcounter{chapter}
%\setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax}
\ifdim\LabelSize>2.5cm\relax
\global\setlength\LabelSize{2.5cm}
\fi}

\Materialtrue%
\ifMaterial%
\ifodd\value{page} %
\backgroundsetup{
angle=90, position={current page.east|-current page text area.north  east}, vshift=8pt, hshift=-\thechapter*\LabelSize,
contents={%
\tikz\node[fill=gray!30,anchor=west,text width=\LabelSize,
align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};  }%
}
\else
\backgroundsetup{
angle=90, position={current page.west|-current page text area.north west}, vshift=-8pt, hshift=-\thechapter*\LabelSize,
contents={%
\tikz\node[fill=gray!30,anchor=west,text width=\LabelSize,
align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter}; }%
}
\fi
\BgMaterial%
\else\relax\fi}%
}

\newcommand\RemoveLabels{\Materialfalse}
\usepackage{afterpage}
\newcommand\RemoveThisLabel{%
\Materialfalse
\afterpage{\global\Materialtrue}%
}

• I'm not able to reproduce the problem with what you have provided, but I've given my best guess – see the notes on how to produce a minimum working example. – Andrew Dunning Jan 22 '19 at 21:40
• Thank you for your comment! I have edited the question. Compilation is with XeLaTeX. The problem only appears if I include a chapter \chapter{A chapter} Some text and \AddLabels  for creating the gray chapter number boxes. – TGterpa Jan 23 '19 at 7:36
• Take a look at that link on MWEs – essentially you want to cut out everything that isn't relevant to the problem (e.g. all the extra bits in your separate preamble). You want to have one (ideally short) piece of text that respondents can paste into their computer to test. – Andrew Dunning Jan 24 '19 at 14:20
• In \AddLabels you are using hshift=-\thechapter*\LabelSize. Here you use \thechapter as a number which is wrong, because it need not be an arabic number. For example in the appendix it is A, B etc. So you have to use either \value{chapter} or the value of another counter related to \chapter. – Schweinebacke Jan 24 '19 at 15:27

KOMA-Script has a more robust approach to adding chapter thumbs using its scrlayer-scrpage package. Download the examples from the KOMA-Script book, and use the files in the Anhang-B folder. Here is a translated version of the example with an appendix added, which will work if the chapterthumb.sty file from the examples is in the same folder:

\documentclass{scrbook}
\usepackage{chapterthumb}
\usepackage{scrlayer-scrpage}

\begin{document}
\chapter{In the beginning it starts}\dots
\chapter{continuing}\dots
\chapter{further}\dots
\chapter{and even further}\dots
\chapter{And always on}\dots
\chapter{Goes the journey}\dots
\chapter{out}\dots
\chapter{And further out}\dots
\chapter{Always further out}\dots

\appendix

\chapter{Until the end}\dots

\end{document}


If you wish to customize it, this has been addressed several times before; see the chapterthumb tag.

• Thank you for your suggestion. I have removed the inclusion of the appendixpackage. However, I just found out that the problem arises when including the gray chapter boxes in the margin using AddLabels. I have edited the question accordingly. – TGterpa Jan 23 '19 at 8:10
• I've modified my answer to show a cleaner method of adding chapter thumbs. – Andrew Dunning Jan 24 '19 at 14:46