我正在从下面的 MWE 创建目录。我希望我定义的部分前缀不应用于简介(见图)。我该怎么做?
\documentclass[a4paper, 12pt]{report}
\usepackage[english]{babel}
\usepackage[titles]{tocloft}
\renewcommand\cftpartfont{\Large\bfseries\scshape}
\renewcommand{\thepart}{\Roman{part} :\\\hfill}
\renewcommand\cftpartpresnum{\centering Part~}
% To Remove page number next to centred heading %
\newcommand{\gobbletocpage}{%
\renewcommand{\addcontentsline}[3]{%
\addtocontents{##1}{\protect\contentsline{##2}{##3}{\relax}}}
}%
\newcommand{\restoretocpage}{%
\renewcommand{\addcontentsline}[3]{%
\addtocontents{##1}{\protect\contentsline{##2}{##3}{\thepage}}}
}%
\begin{document}
\tableofcontents
\setcounter{part}{-1}
\gobbletocpage
\part{Introduction}
\restoretocpage
\chapter{Chapter 1}
\gobbletocpage
\part{This is part 1}
\restoretocpage
\chapter{Chapter 2}
\end{document}
答案1
无论我是否愿意制作这样的目录,你都可以这样做:
\documentclass[a4paper, 12pt]{report}
\usepackage[english]{babel}
\usepackage[titles]{tocloft}
\renewcommand\cftpartfont{\Large\bfseries\scshape\centering}
\renewcommand{\thepart}{\Roman{part}:\\\hfill}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@part}{%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
}{%
\addcontentsline{toc}{part}{\partname~\thepart\hspace{1em}#1}%
}{}{\failed}
\makeatother
\newcommand*{\addpart}[1]{%
\cleardoublepage
\addcontentsline{toc}{part}{\protect\hfill #1}%
\part*{#1}
}
\begin{document}
\tableofcontents
\addpart{Introduction}
\chapter{Chapter 1}
\part{This is part 1}
\chapter{Chapter 2}
\part{This is part 2}
\chapter{Chapter 3}
\end{document}
如果你不想在部分条目中添加页码,只需添加
\renewcommand\cftpartpagefont[1]{}% remove page number
要得到