I am trying to compile a document with
'Sub-tocs' on the first page of each part and each chapter. Gonzalo Medina's solution to a previous question can be used to achieve this.
The appendices typeset as sections on the main toc of a chapter 'Appendices'. Alan Munn has previously solved this.
However, when these two solutions are combined effects occur that I cannot explain, leave alone correct for.
The{tocdepths} for the \parts and \chapters should be {1} and {2}, respectively. This also holds for the appendix. Medina suggests:
\documentclass[twoside,a4paper,12pt]{report}
\usepackage{titlesec,titletoc}
\usepackage[titles]{tocloft}
% take control of the part-page
\titleformat{\part}[display]
{\normalfont\huge\filcenter\bfseries}
{\partname\ \thepart}{0pt}{}
\titleclass{\part}{top}
\begin{document}
\setcounter{tocdepth}{2}
\tableofcontents
\clearpage
\part*{A Part}
\startcontents[parts]
\printcontents[parts]{}{1}{\setcounter{tocdepth}{1}}
\clearpage
\chapter{A Chapter}
\startcontents[chapters]
\printcontents[chapters]{}{}{\setcounter{tocdepth}{2}}
\clearpage
\section{A Section}
\subsection{A Subsection}
\section{B Section}
\subsection{A Subsection}
\stopcontents[chapters]
\chapter{B Chapter}
\section{A Section}
\subsection{A Subsection}
\stopcontents[parts]
%%% The Appendix %%%
\clearpage\phantomsection
\part*{Appendices}
%\addcontentsline{toc}{chapter}{Appendices}
%\addtocontents{toc}{\setcounter{tocdepth}{0}}
%\ChapAsSecOnToc
%\ChapAsChapOnPartoc
\appendix
\startcontents[parts]
\printcontents[parts]{}{}{\setcounter{tocdepth}{1}}
\chapter{An Appendix}
\startcontents[chapters]
\printcontents[chapters]{}{}{\setcounter{tocdepth}{2}}
\clearpage
\section{A Section}
\subsection{A Subsection}
\section{B Section}
\subsection{A Subsection}
\stopcontents[chapters]
\chapter{B Appendix}
\section{A Section}
\subsection{A Subsection}
\stopcontents[parts]
\end{document}
This does the job as desired and leaves the appendix' representation on the toc to be changed.
Adopting Munn's solution to alter the appended chapter's setting on the toc can be done by:
(1) commenting in the four commands below %%% The Appendix %%% in the MWE above and by
(2) defining the following before the beginning of the document:
% store current settings
\newlength{\truechapindent}
\setlength{\truechapindent}{\cftchapindent}
\newlength{\truebeforechapskip}
\setlength{\truebeforechapskip}{\cftbeforechapskip}
\let\truechapfont\protect\cftchapfont
\newcounter{truechapdotsep}
\setcounter{truechapdotsep}{\cftchapdotsep}
% chapter to look like section on toc
\newcommand{\ChapAsSecOnToc}{
\addtocontents{toc}{
\setlength{\cftbeforechapskip}{\cftbeforesecskip}
\setlength{\cftchapindent}{\cftsecindent}
\protect\renewcommand{\cftchapfont}{\cftsecfont}
\protect\renewcommand{\protect\cftchapdotsep}{\cftsecdotsep}
}}
% chapter still to look like chapter on partoc
\newcommand{\ChapAsChapOnPartoc}{
\addtocontents{ptc}{
\setlength{\cftbeforechapskip}{\truebeforechapskip}
\setlength{\cftchapindent}{\truechapindent}
\protect\renewcommand{\cftchapfont}{\truechapfont}
\protect\renewcommand{\protect\cftchapdotsep}{\value{truechapdotsep}}
}}
Now I run into two problems:
- Resetting the
{tocdepth}with\printcontents[XX]{}{}{\setcounter{tocdepth}{YY}}doesn't have an effect any longer, ie the{tocdepth}remains{0}- The chapters are not set in bold in the Appendices' part-toc
How do I address problems (1) and (2)?
I tried to mitigate the first by replacing \printcontent's fourth argument with {\addtocontents{ptc}{\setcounter{tocdepth}{YY}}}. But now the last depth written to the .ptc file overwrites the first. And the chapters are still not set in bold in the Appendices part-toc.
However, it makes 4 of 5 pages look the way I want them to:



