1

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?

  • Whatever you have shared in the MWE part, after compiling that the output is pretty normal. – Mishra S Feb 22 at 12:57
  • For the second appendix, you can try the command \noindent – Mishra S Feb 22 at 12:57
  • 1
    @SibaMishra But I like to have the indent at the first ;) – S-Man Feb 22 at 13:04
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.