考虑一下代码
\documentclass{book}
\usepackage{tocloft}
\let\cleardoublepage\clearpage % Clears all blank pages
\renewcommand\cftchapafterpnum{\vspace*{5pt}} % Space after each Chapter in the Table of Contents
\renewcommand\cftsecafterpnum{\vspace*{7pt}} % Space after each Section
\cftpagenumbersoff{chapter} % Turns off Chapter Page in TOC.
\begin{document}
\tableofcontents
\chapter*{1}
\addcontentsline{toc}{chapter}{CHAPTER 1---DESCRIPTION}
\section*{1}
\addcontentsline{toc}{section}{Section 1 Title}
% NOW, I WOULD LIKE TO TURN ON CHAPTER PAGE # and ADD a DOTFILL in the TOC.
\addtocontents{toc}{\cftpagenumberson{chapter}}%Turns chapter pg. numbers ON
% % % BUT---HOW TO ADD A DOTFILL?
\chapter*{2}
\addcontentsline{toc}{chapter}{CHAPTER 2---DESCRIPTION}
\end{document}
生成目录:
我已经能够使用命令添加从第二章开始的页码\addtocontents{toc}{\cftpagenumberson{chapter}}
,但我无法弄清楚如何dotfill
为相同的第二章添加目录---当之前没有点填充时。
问题:如何为第二章目录条目添加点填充?
谢谢。
答案1
通过添加\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
到序言中,在调用时将生成一个点填充\addtocontents{toc}{\cftpagenumberson{chapter}}
以返回页码。
因此,在添加了几章内容后,代码
\documentclass{book}
\usepackage{tocloft}
\let\cleardoublepage\clearpage % Clears all blank pages
\renewcommand\cftchapafterpnum{\vspace*{5pt}} % Space after each Chapter in the Table of Contents
\renewcommand\cftsecafterpnum{\vspace*{7pt}} % Space after each Section
\cftpagenumbersoff{chapter} % Turns off Chapter Page in TOC.
% TO ADD DOTFILL (BEGINNING) WITH CHAPTER 2.
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\begin{document}
\tableofcontents
\chapter*{1}
\addcontentsline{toc}{chapter}{CHAPTER 1---DESCRIPTION}
\section*{1}
\addcontentsline{toc}{section}{Section 1 Title}
% TURN ON CHAPTER PAGE# (which "kicks in" the DOTFILL of the above \renewcommand)
\addtocontents{toc}{\cftpagenumberson{chapter}}%Turns chapter pg. numbers ON
\chapter*{2}
\addcontentsline{toc}{chapter}{CHAPTER 2---DESCRIPTION}
\chapter*{3}
\addcontentsline{toc}{chapter}{CHAPTER 3---DESCRIPTION}
\chapter*{4}
\addcontentsline{toc}{chapter}{CHAPTER 4---DESCRIPTION}
\end{document}
现在生成目录: