我正在尝试使用该包设置我的目录tocloft
(使用这个问题作为指导)得到如下结果:
这是我目前所做的
\documentclass[10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[paperheight=210mm,paperwidth=170mm,left=2cm,right=1.78cm,top=2.03cm,bottom=1.95cm,heightrounded]{geometry}
\usepackage{tocloft}
\makeatletter
\let\stdl@chapter\l@chapter
\renewcommand*{\l@chapter}[1]{\stdl@chapter{\hfill\underline{#1}}{}}
\makeatother
\setcounter{tocdepth}{2}
\begin{document}
\tableofcontents
\chapter{Hello}
\section{Hi}
\chapter{Goodbye}
\section{See you soon}
\end{document}
答案1
下面的操作我认为是您想要的。
% tocchapprob.tex SE 634861
\documentclass[10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[paperheight=210mm,paperwidth=170mm,left=2cm,right=1.78cm,top=2.03cm,bottom=1.95cm,heightrounded]{geometry}
\usepackage{tocloft}
\makeatletter
%\let\stdl@chapter\l@chapter
%\renewcommand*{\l@chapter}[1]{\stdl@chapter{\hfill\underline{#1}}{}}
\makeatother
\setcounter{tocdepth}{2}
%% eventually the number of the next chapter
\newcounter{nextchap}
%% set nextchap to the number of the next chapter
\newcommand{\incchap}{\setcounter{nextchap}{\value{chapter}}\addtocounter{nextchap}{1}}
%% add centered Chapter number into the ToC
%\newcommand{\addchaptoc}{\addtocontents{toc}{%
% \vspace{\baselineskip}\centering \underline{\textbf{Chapter \Roman{nextchap}}}\par}
\begin{document}
\tableofcontents
% get the number of the next chapter
\incchap
% add centered Chapter number into the ToC
\addtocontents{toc}{\vspace{\baselineskip}\centering \underline{\textbf{Chapter \Roman{nextchap}}}\par}
\chapter{Hello}
\section{Hi}
Sectional text.
Nextchap is \thenextchap, and chapter is \thechapter.
\incchap
\addtocontents{toc}{\vspace{\baselineskip}\centering \underline{\textbf{Chapter \Roman{nextchap}}}\par}
\chapter{Goodbye}
Nextchap is \thenextchap, and chapter is \thechapter.
\section{See you soon}
\end{document}
您或许可以让用户界面稍微简单一些,但这取决于您。
编辑如果您希望在章节标题和页码之间添加点引导,请将其添加\renewcommand{\cftchapdotsep}{\cftdotsep}
到您的序言中。