![将章节添加到 ToC 时 memoir 和 titletoc 包出现错误](https://linux22.com/image/404836/%E5%B0%86%E7%AB%A0%E8%8A%82%E6%B7%BB%E5%8A%A0%E5%88%B0%20ToC%20%E6%97%B6%20memoir%20%E5%92%8C%20titletoc%20%E5%8C%85%E5%87%BA%E7%8E%B0%E9%94%99%E8%AF%AF.png)
我正在使用回忆录文档类,并尝试自定义目录样式。为此,我使用包titletoc
和命令\titlecontents
进行格式化。对于可以正常工作,section
而subsection
对于则失败chapter
,并出现以下错误:
! Undefined control sequence.
<argument> \@chapapp@head
\@cftbsnum 1\@cftasnum
l.3 ...er}{\chapternumberline {1}first chapter}{3}%
?
这是为我重现错误的 MWE。pdflatex 和 lualatex 都出现了这种情况(至少我没有尝试其他的)。如果\documentclass{memoir}
将 替换为\documentclass{book}
,则一切正常。
\documentclass{memoir}
\usepackage{titletoc}
\titlecontents{chapter}[0pt]{\vskip0pt}{\small\thecontentslabel.\ }{}{\small\dotfill\contentspage}
\titlecontents{section}[0pt]{\vskip0pt}{\qquad\small\thecontentslabel.\ }{}{\small\dotfill\contentspage}
\titlecontents{subsection}[0pt]{\vskip0pt}{\qquad \qquad \small\thecontentslabel.\ }{}{\small\dotfill\contentspage}
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
\begin{document}
\tableofcontents
\listoffigures
test
\chapter{first chapter}
Contents of first chapter.
\section{first section}
Contents of first section.
\chapter{second chapter}
contents of second chapter.
\section{second section}
Contents of second section.
\subsection{First subsection}
Contents of first subsection
\end{document}
答案1
据我所知,这似乎可以解决问题。我不太确定是否需要重新定义方框,但你可以忽略它
\documentclass{memoir}
\renewcommand\cftchapterfont{\normalfont\small}
\renewcommand{\cftchapterleader}{\cftdotfill{\cftchapterdotsep}}
\renewcommand{\cftchapterdotsep}{\cftdotsep}
\renewcommand{\cftchapterpagefont}{\normalfont\small}
\renewcommand{\cftchapteraftersnum}{.\ }
\setlength\cftbeforechapterskip{0pt}
\renewcommand\cftsectionfont{\normalfont\small}
\renewcommand\cftsubsectionfont{\normalfont\small}
\renewcommand\cftsubsubsectionfont{\normalfont\small}
\renewcommand{\cftsectionaftersnum}{.\ }
\renewcommand{\cftsubsectionaftersnum}{.\ }
\renewcommand{\cftsubsubsectionaftersnum}{.\ }
\renewcommand\numberlinebox[2]{#2}
\renewcommand\chapternumberlinebox[2]{#2}
\settocdepth{subsubsection}
\setsecnumdepth{subsubsection}
\begin{document}
\tableofcontents*
\listoffigures*
test
\chapter{first chapter}
Contents of first chapter.
\section{first section}
Contents of first section.
\chapter{second chapter}
contents of second chapter.
\section{second section}
Contents of second section.
\subsection{First subsection}
Contents of first subsection
\end{document}
答案2
我注意到您的评论中您希望元素大写,而 daleif 的答案并没有做到这一点,尽管它做了您想要的其他事情。要使章节条目大写,请执行以下操作:
\renewcommand{\cftchapterfont}{\normalfont\small\MakeUppercase}
并以同样的方式添加\MakeUppercase
到\cftsectionfont
、\cftsubsectionfont
等。