我問如何為附錄的目錄行添加縮進這裡。
在我的真實結構中,我包括了附錄:
\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}
但這最終是:
Contents
1 My Chapter 3
Appendices 5
A One appendix header 7
B Another appendix header 9
縮排對於第一個包含不起作用。有什麼解決辦法嗎?
答案1
你可以藉用 Martin Scharrer 來解決這個問題\immaddtocontents
宏:
\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}