tocloft を使用せずに目次のタイトルを中央に配置するにはどうすればよいでしょうか?

tocloft を使用せずに目次のタイトルを中央に配置するにはどうすればよいでしょうか?

私は単に「本」文書の目次のタイトルを中央に配置したいだけです。

目次にドット リーダーを追加しましたが、これは、パッケージを使用せずにtocloft、代わりにコンパニオン パッケージ\dottedcontentsのコマンドを使用することによって最も効果的に実現できるようです。titlesectitletoc

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

tocloftTOC タイトルを中央に配置するための設定を導入すると、垂直配置/間隔の問題が発生するようですが、これを修正する方法がわかりません (これは、以下の Peter の回答に対する私のコメントで詳しく説明されています)。したがって、tocloft可能であれば、このパッケージの使用を避けたいと思います。

センタリングタスクに取り組む 1 つの方法は、パッケージの\centeringchapter コマンドに以下を追加することです。\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の後に、グループ内でを宣言できます\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、および LoT にtocloft標準クラスの ( bookreport、 ) 設定を使用します。 以下は (タイプミスを除いて) を使用した問題の解決策です。articletocloft

\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}

これにより、エントリのインデントと垂直配置は変更されません。

関連情報