[Tex/LaTex] Appendix Chapters typeset as Sections in ToC

appendicestable of contentstocloft

I am very new to LaTeX and still more in a trial and error phase than on a real understanding level.

My goal is to have all appendices – which are chapters and I would like to keep it that way – to appear in the TOC as sections, under a 'chapter' appendices.

Here is what I tried, using the tocloft package

\newpage\phantomsection
\addcontentsline{toc}{chapter}{Appendices}
\appendix

\setlength{\cftchapindent}{\cftsecindent}
\renewcommand{\cftchapfont}{\cftsecfont}
\renewcommand{\cftchapleader}{\cftsecleader}

\chapter{chapter title}

So my idea was to just tell LaTeX to write chapters to the TOC as though they were sections. My code has no effect whatsoever. Any ideas/solutions are very much appreciated

Best Answer

You had the right idea, but you need to add your changes to the TOC itself rather than in the main document (and because of this you need to \protect some of the commands.) Note that this solution won't look very nice if your appendices have sections.

\documentclass{report}
\usepackage{tocloft}
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A section}
\newpage\phantomsection
\addcontentsline{toc}{chapter}{Appendices}
\appendix
\addtocontents{toc}{
\setlength{\cftbeforechapskip}{\cftbeforesecskip}
\setlength{\cftchapindent}{\cftsecindent}
\protect\renewcommand{\cftchapfont}{\cftsecfont}
\protect\renewcommand{\protect\cftchapdotsep}{\cftsecdotsep}
}
\chapter{An Appendix}
\end{document}

partial output of code