I add contents lines containing the chapter numbers in the list of figures of a document, by using the third answer of the following question:
Include chapters in List of Figures with titletoc?
All is good except when I add an appendix, where I have the following error message:
! Missing number, treated as zero.! You can't use \numexpr in horizontal mode. \ifnumcomp ...\ifnum \numexpr #1\relax #2\numexpr...
but it compiles good ! so it gives the desired result despite the error message !
What's the cause of this error message, and how can I avoid it ?
I give the original file, where I only add the command for appendix:
\documentclass{book}
\usepackage{etoolbox}
\usepackage[toc,page]{appendix} %% ADDED TO THE ORIGINAL FILE
\makeatletter
\def\thischaptertitle{}
\apptocmd{@chapter}{\gdef\thischaptertitle{#1}}{}{}
\newcommand{\DeclareDividedList}[1]%
{\newcounter{#1@chapter}\setcounter{#1@chapter}{0}}
\pretocmd{\addcontentsline}%
{\ifltxcounter{#1@chapter}%
{%
\ifnumgreater{\thechapter}{\value{#1@chapter}}{%
\setcounter{#1@chapter}{\thechapter}%
\addtocontents{#1}{\protect\contentsline{chapter}%
{\protect\numberline {\thechapter} {\thischaptertitle}}{}{} }
}{}%
}{}%
}{}{}
\makeatother
\DeclareDividedList{lof}
\DeclareDividedList{lot}
\usepackage[paperheight=12cm,vscale=0.9]{geometry}
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\mainmatter
\chapter{Introduction with no Figures}
\chapter{Test Chapter with Figures but no Tables}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\chapter{Test Chapter with Tables but no Figures}
\begin{table}
\caption{caption text}
\end{table}
\begin{table}
\caption{caption text}
\end{table}
\chapter{Test Chapter with Figures and Tables}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}
%%% ADDED APPENDIX
\begin{appendices}
\renewcommand{\chaptername}{Appendix}
\chapter{Appendix One}
\begin{figure}
\caption{Figure 1 of appendix 1}
\end{figure}
\end{appendices}
\end{document}
and the result obtained:
