2

I asked how to add an indent to a toc line for an appendix here.

In my real structure I am including the appendices:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{tocloft}
\usepackage[title,toc,page]{appendix}

\begin{document}

\tableofcontents

\chapter{MyChapter}

\begin{appendices}
\addtocontents{toc}{\protect\setlength{\cftchapindent}{3em}}
\include{appendix_a}
\include{appendix_b}
\end{appendices}

\end{document}

But this ends in:

Contents

1 My Chapter                      3
Appendices                        5
A One appendix header             7
    B Another appendix header     9

The indent does not work for the first include. Is there any solution?

S-Man
  • 275

1 Answers1

3

You can fix that by borrowing Martin Scharrer's \immaddtocontents macro:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tocloft}
\usepackage[title,toc,page]{appendix}

\makeatletter 
\newcommand\immaddtocontents[1]{{%
   \let\protect\@unexpandable@protect
   \immediate\write\@auxout{\noexpand\@writefile{toc}{#1}}%
}}
\makeatother

\begin{document}

\tableofcontents

\chapter{MyChapter}

\begin{appendices}
\immaddtocontents{\protect\setlength{\cftchapindent}{3em}}
\include{appendix_a}
\include{appendix_b}
\end{appendices}

\end{document}

enter image description here

DG'
  • 21,727