tocloft를 사용하지 않고 목차 제목을 중앙에 어떻게 배치합니까?

tocloft를 사용하지 않고 목차 제목을 중앙에 어떻게 배치합니까?

나는 "책" 문서의 목차 제목을 중앙에 두고 싶습니다.

방금 목차에 점선을 추가했는데 패키지를 사용하지 tocloft않고 대신 동반 패키지 \dottedcontents의 명령을 사용하는 것이 가장 좋은 것처럼 보였습니다 . 다음과 같습니다.titlesectitletoc

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

목차 제목을 중앙에 배치하기 위해 설정을 도입하면 tocloft수직 배치/간격 문제가 발생하여 수정 방법을 잘 모르겠습니다(이 내용은 아래 Peter의 답변에 대한 내 의견에 자세히 설명되어 있습니다). 따라서 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그룹 내에서 을 선언할 수 있습니다 \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표준 클래스의 ( book, report, ) 설정을 사용합니다. 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}

이렇게 하면 항목의 들여쓰기 및 수직 배치가 변경되지 않습니다.

관련 정보