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?

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

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .