我想自定义部分标题,以便让标题在目录中居中。我该怎么做?
\documentclass[hidelinks,12pt,twoside,openright,a4paper]{book}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{3pt}%espace entre chapitres
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fancyhdr}
\pagestyle{fancy}
% We don’t want chapter and section numbers
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{} % sets both header and footer to nothing
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{A title}} % even pages: chapter title
\fancyhead[CO]{\textit\leftmark} % odd pages: book title
\begin{document}
\title{A title}
\author{A name}
\date{}
\maketitle
\tableofcontents
\frontmatter
\part{Why is Latex so complicated?}
\chapter{A chapter}
\lipsum
\mainmatter
\part{How to customize a part section?}
\chapter{Another chapter}
\lipsum
\backmatter
\end{document}
答案1
尝试这个:
% tocpartprob.tex SE 649116
\documentclass[hidelinks,12pt,twoside,openright,a4paper]{book}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{tocloft}
%%%% center part titles
\renewcommand{\cftpartfont}{\hfil\bfseries}
\renewcommand{\cftpartleader}{\hfil}
\setlength{\cftbeforechapskip}{3pt}%espace entre chapitres
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fancyhdr}
\pagestyle{fancy}
% We don’t want chapter and section numbers
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{} % sets both header and footer to nothing
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{A title}} % even pages: chapter title
\fancyhead[CO]{\textit\leftmark} % odd pages: book title
\setlength{\headheight}{15pt} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\title{A title}
\author{A name}
\date{}
\maketitle
\tableofcontents
\frontmatter
\part{Why is Latex so complicated?}
\chapter{A chapter}
\lipsum
\mainmatter
\part{How to customize a part section?}
\chapter{Another chapter}
\lipsum
\backmatter
\end{document}
感谢 MWE,我对其进行了少许修改。