首先,MWE 及其输出如下。
\documentclass{book}
\begin{document}
\tableofcontents
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\begin{appendix}
\chapter{Basic Concepts}
\section{Theory}
\end{appendix}
\end{document}
我想改进输出的两点:
- 在目录中的数字前添加“章节”或“附录”;
- 使章节和附录标题(不带章节或附录字样)或编号缩进相同。
我发现的两个问题的解决方案几乎都诉诸于tocloft
不受欢迎的方案,例如
\usepackage{tocloft}%
\usepackage{calc}%widthof
%add Chapter before numbers in Contents
\renewcommand\cftchappresnum{\chaptername\space}
%change Chapter to Appendix before numbers in Contents
\makeatletter
\g@addto@macro\appendix{%
\addtocontents{toc}{%
\protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
}%
}
\makeatother
%make chapter and appendix titles without the words Chapter or Appendix or numbers be indent larger
\setlength{\cftchapnumwidth}{\widthof{\textbf{Appendix\space00\space}}}
那么有没有什么解决方案,不调用或者使用尽可能少的包来尽可能少地tocloft
改变默认命令?\tableofconts
答案1
您可以修补该命令\@chapter
和该命令\l@chapter
:
\documentclass{book}
\usepackage{etoolbox}
\newlength{\chapnwd}
\settowidth{\chapnwd}{\textbf{Appendix\space00\space}}
\makeatletter
\patchcmd{\@chapter}{\protect\numberline{\thechapter}#1}{\protect\numberline{\@chapapp\space\thechapter\space}#1}{\@latex@info{true}}{\@latex@info{false}}
\patchcmd{\l@chapter}{\setlength\@tempdima{1.5em}}{\setlength\@tempdima{\chapnwd}}{\@latex@info{true}}{\@latex@info{false}}
\makeatother
\begin{document}
\tableofcontents
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter*{test}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\begin{appendix}
\chapter{Basic Concepts}
\section{Theory}
\end{appendix}
\end{document}
答案2
您还没有明确说明“线路扩展”的含义。您还没有说明您的问题所在,tocloft
所以我只能猜测这应该对您有用。
% tocloftprob.tex SE 645714
\documentclass{book}
\usepackage%[titles] % this option does not reset the title spacing
{tocloft}
\addtolength{\cftchapnumwidth}{7em} % space for Chapter/Appendix number
\renewcommand{\cftchappresnum}{Chapter }
\begin{document}
\tableofcontents
\chapter{Basic Concepts}
\section{Theory}
\chapter{Basic Concepts}
\section{Theory}
\begin{appendix}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{Appendix }}
\chapter{Basic Concepts}
\section{Theory}
\end{appendix}
\end{document}