如果这个问题太具体,我深感抱歉。
我正在尝试使用自定义的“部分标题页”(使用 titlesec)在目录中实现居中的“部分”标题(使用 xpatch)。我发现我无法同时使它们工作。
我在下面放置了一个 MWE,其中我已实现了目录中想要的居中部分标题,但使用了标准部分标题页。如果我取消注释“带有题词的自定义部分标题页”块,我会在每个部分的开头获得我想要的外观,但目录已恢复为左对齐部分标题。
我尝试过切换这些代码块的顺序,但没有成功。如有任何建议,我将不胜感激。
\documentclass[a4paper,12pt]{book}
\usepackage{lipsum} % lorum ipsum
\usepackage{titlesec}
\usepackage{epigraph} % quotes at the beginning of parts
\usepackage{xpatch} % used for patching part to allow multi-line centred part titles in toc.
% Centered Part titles in toc
\DeclareRobustCommand{\wrapmytitles}[1]{%
\leavevmode
\centering
\parbox{0.8\linewidth}{\centering #1}%
}
%
\makeatletter
\xpatchcmd{\@part}{%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
}{%
\addtocontents{toc}{\begingroup\vspace{5mm}\large \bfseries\scshape\protect\centering\underline{\partname\ \thepart}\par\vspace{-5mm}\large\bfseries\scshape\wrapmytitles{#1}\par\vspace{5mm}\endgroup}
}{}{}
\makeatother
% Custom part-title-pages with epigraph
%\titleclass{\part}{top}
%\titleformat{\part}
%[display]
%{\centering\Huge\bfseries}{\titlerule[5pt]\vspace{3pt}\titlerule[2pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
%{0pt}
%{\titlerule[2pt]\vspace{1pc}\huge\MakeUppercase}
%[\vspace{2ex}\titlerule {\thispagestyle{epigraph}}\vspace{10cm}]
%\titlespacing*{\part}{0pt}{0pt}{0pt}
%\setlength\epigraphwidth{.9\textwidth}
%\renewcommand{\epigraphflush}{center}
\begin{document}
\title{Minimum not-working example}
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\epigraphhead[450]{\centering \it{A truly awe-inspiring quote}\par\hfill\textsc{--- Some guy}}
\part{alpha}
\chapter{one}
\lipsum
\chapter{two}
\lipsum
\pagebreak
\epigraphhead[450]{\centering \it{Another great quote
}\par\hfill\textsc{--- Some girl}}
\part{beta}
\chapter{three}
\lipsum
\chapter{four}
\lipsum
\end{document}
答案1
就是这样。我做了一些修改:我不明白你为什么要修改类,\part
因为top
你的部分都在一页上,所以我删除了它。另外,我认为部分页面上没有页码更好;为此我不得不修补命令\epigraphhead
。如果你更喜欢页码,你只需要删除补丁。
\documentclass[a4paper,12pt]{book}
\usepackage{lipsum} % lorum ipsum
\usepackage[newparttoc, clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{epigraph} % quotes at the beginning of parts
\usepackage{xpatch} % used for patching \epigraphhead to have the empty page style on part g3pages.
% Centered Part titles in toc
\DeclareRobustCommand{\wrapmytitles}[1]{%
\leavevmode
\centering
\parbox{0.8\linewidth}{\centering #1}%
}
\xpatchcmd{\epigraphhead}{\hfil\thepage\hfil}{}{}{}
% Custom part-title-pages with epigraph
\titleformat{\part}
[display]
{\centering\Huge\bfseries}{\titlerule[5pt]\vspace{3pt}\titlerule[2pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
{0pt}
{\titlerule[2pt]\vspace{1pc}\huge\MakeUppercase}
[\vspace{2ex}\titlerule {\thispagestyle{epigraph}}\vspace{10cm}]
\titlespacing*{\part}{0pt}{0pt}{0pt}
\setlength\epigraphwidth{.9\textwidth}
\renewcommand{\epigraphflush}{center}
\titlecontents{part}[0pt]{\addvspace{2pc}\centering\large\bfseries}{\partname~\thecontentslabel \endgraf}{}{}%
\begin{document}
\title{Minimum not-working example}
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\epigraphhead[450]{\centering \it{A truly awe-inspiring quote}\par\hfill\textsc{--- Some guy}}
\part{Alpha}
\chapter{One}
\lipsum
\chapter{Two}
\lipsum
\pagebreak
\epigraphhead[450]{\centering \it{Another great quote}\par\hfill\textsc{--- Some girl}}
\part{Beta}
\chapter{Three}
\lipsum
\chapter{Four}
\lipsum
\end{document}