我怎样才能将标题章节放在目录的中央?

我怎样才能将标题章节放在目录的中央?

我正在尝试格式化,\tableofcontents我想将章节标题放在Topological spaces中心位置Chapter 1,...就像这张图片一样,但我无法得到结果。

我的代码

\documentclass[12pt,a4paper,twoside,openany]{book}
\usepackage[unicode,bookmarksnumbered]{hyperref}
\usepackage{lipsum}

\renewcommand*{\thesection}{\S\arabic{section}}
\renewcommand*{\thesubsection}{\thesection.\arabic{subsection}}

\usepackage{sectsty} 

\allsectionsfont{\centering}

\usepackage{fancyhdr}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\itshape\nouppercase{\rightmark}}
\fancyhead[RE]{\itshape\nouppercase{\leftmark}}


\usepackage{tocloft,calc}
\usepackage{etoolbox}
\renewcommand{\cftchappresnum}{\chaptername\space}
\setlength{\cftchapnumwidth}{\widthof{\textbf{Appendix~999~}}}
\makeatletter
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
  }%
}
\makeatother
\AtBeginDocument{\renewcommand{\chaptername}{Chapter}}
\begin{document}
\tableofcontents
\chapter{Topological spaces}
\section{Hello again}
    \subsection{Something}
\section{Something}
\lipsum[1-3]
\subsection{Something}
\section{A section}
\lipsum[1-3]

\appendix
\chapter{Hello again}
\section{Hello again}
\lipsum[1-10]
\chapter{Hello again}
    \end{document}

在此处输入图片描述

在此处输入图片描述

答案1

使用该tocloft包来调整目录中部门标题的样式和位置。

\documentclass{book}
\usepackage{tocloft}

\renewcommand{\cftchappresnum}{CHAPTER } % put CHAPTER before the number
\renewcommand{\cftchapfont}{\centering} % center CHAPTER and number
\makeatletter
% start new line after the number, shift title so it is centered
\renewcommand{\cftchapaftersnumb}{%
    \\ \hspace{\@pnumwidth}\hspace{\@tocrmarg} \hfil\bfseries\large}
\makeatother
\renewcommand{\cftchapleader}{\hfill}
\cftpagenumbersoff{chapter} % no page numbers for chapters
\renewcommand{\cftchapafterpnum}{\cftparfillskip}

\renewcommand{\cftsecpresnum}{\S\ } % put section symbol before section numbers

% then remainder of preamble and document

欲了解更多信息,请阅读手册(> texdoc tocloft)。

在此处输入图片描述

相关内容