Including an appendix chapter using \include{chapter_appendixA} results in a 'weird error' in overleaf (compiling with XeLaTeX):
! Missing number, treated as zero.
pl.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
\rehead{\small{Chapter \thechapter}}
\chapter{A chapter}
Some text
\AddLabels
%%%%%%%%%%%%%%
%% 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
\usepackage[headsepline=true]{scrlayer-scrpage}
\clearpairofpagestyles
%%%%%%%%%%%%%%%%%%%%%%%
%% chapter numbering %%
%%%%%%%%%%%%%%%%%%%%%%%
%\renewcommand*{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
% Create header for odd (o) and even (e) pages
\lehead{\thepage}\rohead{\thepage}
\lohead{{\small\rightmark}}
\setkomafont{pagehead}{\normalfont\normalcolor}
\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}
\newcommand\AddLabels{%
\Materialtrue%
\AddEverypageHook{%
\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}%
}


\chapter{A chapter} Some textand\AddLabelsfor creating the gray chapter number boxes. – TGterpa Jan 23 '19 at 07:36\AddLabelsyou are usinghshift=-\thechapter*\LabelSize. Here you use\thechapteras a number which is wrong, because it need not be an arabic number. For example in the appendix it isA,Betc. So you have to use either\value{chapter}or the value of another counter related to\chapter. – Schweinebacke Jan 24 '19 at 15:27