如何使用书籍类获取目录中的虚线引线

如何使用书籍类获取目录中的虚线引线

我正在使用书籍类,我需要在目录中为章节添加虚线引线。tocloft 包似乎不起作用。我正在使用 TexShop。

我目前有这个:

\documentclass[12pt, oneside]{book}

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\end{mainmatter}
\end{document}

章节有虚线引言,但章节没有。

我尝试过包含该tocloft包但无法让它工作:

\documentclass[12pt, oneside]{book}

\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\end{mainmatter}
\end{document}

我收到一条错误消息,提示“未定义控制序列”

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded                         format=pdflatex)
 restricted \write18 enabled.
 entering extended mode
(./testingTOC.tex
LaTeX2e <2015/01/01>
Babel <3.9l> and hyphenation patterns for 21 languages loaded.
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/book.cls
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/bk12.clo))
(./tocloft.sty (./stdclsdv.sty)) (./testingTOC.aux) (./testingTOC.toc
./testingTOC.toc:1: Undefined control sequence.
\cftchapleader ->\cftdotfill 
                         {\cftdotsep }
l.1 ...line {chapter}{\numberline {1}Chapter 1}{1}

? ]

答案1

这就是我最终开始工作的结果:

\documentclass[12pt, oneside]{book}
\usepackage{tocloft}
\renewcommand\cftchapdotsep{\cftdotsep}

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\end{mainmatter}
\end{document}

答案2

这是一个无需 的解决方案tocloft,通过重新定义\l@chapter,在里面添加\@dottedtocline命令并调整水平跳过。

\documentclass[12pt, oneside]{book}

\usepackage{showframe}
\makeatletter

\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
  \addpenalty{-\@highpenalty}%
  \begingroup
  \parindent\z@ 
  \rightskip\@pnumwidth
  \parfillskip -\@pnumwidth
  \leavevmode  
  \@dottedtocline{0}{0em}{1.5em}{%
    \bfseries #1}{\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}}%
  \penalty\@highpenalty
  \endgroup
  \fi
}
\makeatother

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\chapter{Chapter with a very long title that is completely useless but we will try it }
\section{section 1}
\subsection{subsection}

\end{mainmatter}
\end{document}

在此处输入图片描述

相关内容