如何在不使用 tocloft 的情況下使目錄標題居中?

如何在不使用 tocloft 的情況下使目錄標題居中?

我只想將目錄標題放在我的“書籍”文件的中心。

我剛剛將點引導符添加到目錄中,這似乎是通過放棄該tocloft包並使用配套包\dottedcontents的命令來最好地完成的,如下所示:titlesectitletoc

\dottedcontents{chapter}[0em]{\vspace{2.1ex}}{0em}{0.5pc}

引入tocloft設定以使目錄標題居中會導致垂直放置/間距問題,我不確定如何修正(這在我對下面彼得的回答的評論中詳細描述)。因此,如果可能的話,我想避免使用該tocloft包。

處理居中任務的一種方法是添加到套件的\centering章節命令中:\titleformattitlesec

\usepackage{titlesec}
\titleformat{\chapter}[display]{\centering\Large\bfseries}{}{}{}

然而,這集中了所有章節標題,我不想要這樣。

所以,我的問題是:在不影響其他章節標題且不使用 的情況下將目錄標題居中的最簡單方法是什麼tocloft

這是一個近乎最小的範例(省略了我使用該tocloft套件的嘗試):

\documentclass{book}

\usepackage{titlesec}
\titleformat{\chapter}[display]{\Large\bfseries}{}{}{}

\usepackage{indentfirst}

\usepackage{titletoc}
\dottedcontents{chapter}[0em]{\vspace{2.1ex}}{0em}{0.5pc}

\begin{document}

\tableofcontents
\vspace{24pt}

\chapter*{Left-Justified Chapter 1}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 1}

Some indented text.

\chapter*{Left-Justified Chapter 2}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 2}

More indented text.

\end{document}

答案1

您可以\titleformat在群組內聲明 a 之後\begin{document}

無關:使用配套包titletoc,您可以使用命令以更簡單的方式格式化目錄中的條目\dottedcontents

\documentclass{book}

\usepackage{titlesec, titletoc, xcolor}
\titleformat{\chapter}[display]{\Large\bfseries}{}{}{}

\usepackage{indentfirst}

\dottedcontents{chapter}[3.8em]{\vspace{2ex}}{2.3em}{0.8pc}

\begin{document}

\begingroup
\titleformat{\chapter}[block]{\Large\bfseries\filcenter}{\color{red}}{}{}
\tableofcontents
\vspace{24pt}
\endgroup

\chapter*{Left-Justified Chapter 1}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 1}

Some indented text.

\chapter*{Left-Justified Chapter 2}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 2}

More indented text.

\end{document} 

在此輸入影像描述

答案2

預設情況下,該套件使用ToC、LoF 和 LoTtocloft標準類別的 ( bookreport、 ) 設定。article以下(減去任何拼字錯誤)是使用 解決您的問題的方法tocloft

\documentclass{book}
\usepackage{tocloft}

%% center Contents title
\renewcommand{\cfttoctitlefont}{\hfill\Huge\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}

%% add dot leaders to chapters
\renewcommand{\cftchapdotsep}{\cftdotsep}

\begin{document}
\tableofcontents
\chapter{First chapter}
\section{A section}
\subsection{A subsection}
\end{document}

這不會改變條目的縮排和垂直位置。

相關內容