我正在尝试格式化,\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
)。