hyperref 是否完全证明了目录中各部分的合理性?

hyperref 是否完全证明了目录中各部分的合理性?

下面的 MWE 按照我想要的方式将目录居中,除了\usepackage{hyperref}完全对齐各部分。例如,“第一部分:第一部分”是完全对齐的:

在此处输入图片描述

当我注释掉\usepackage{hyperref}这些部分时,它们会按照我希望的方式居中:

在此处输入图片描述

如何在使用时使零件不完全对齐hyperref

\documentclass{memoir}
% \usepackage{hyperref}
\let\ordinal\relax

\makeatletter
\renewcommand{\printtoctitle}[1]{\centering\HUGE\textit{Contents}}

% Chapter
\usepackage{fmtcount}
\renewcommand{\thechapter}{\Numberstring{chapter}}
\renewcommand{\cftchapterleader}{}
\renewcommand{\cftchapterfillnum}[1]{\hspace*{10pt}\huge#1\cftparfillskip\par}
\renewcommand*{\cftchapterfont}{}
\renewcommand\chapternumberline[1]{\hfil\Large\emph{#1}\hfil\strut\huge\par\nopagebreak\hfil}

% Part
\renewcommand{\cftpartleader}{}
\renewcommand*{\cftpartfont}{}%
\renewcommand\partnumberline[1]{\centering\huge\scshape Part #1: }
\renewcommand*{\cftpartformatpnum}[1]{}%
\renewcommand{\thepart}{\Numberstring{part}}

\patchcmd\l@part{%
  {\cftpartfont {#1}}\cftpartfillnum{#2}%
}{%
  #1\cftpartfillnum{#2}%
}{\typeout{patched}%
}{}

% Spacing
\setlength{\cftbeforechapterskip}{0pt}
\setlength{\cftbeforepartskip}{50pt}

% Document
\begin{document}
\tableofcontents*
\chapter*[Introduction]{Introduction}
\part{The First Part}
\chapter{The First Chapter}
\end{document}

答案1

正如评论中所述,我没有意识到patchcmd问题出在我这里。我删除了它,并通过插入一些 s 实现了相同的效果,\hfil如我更新的 MWE 中所示。

在此处输入图片描述

\documentclass{memoir}
\usepackage{hyperref} % <<===== This causes formatting issue
\let\ordinal\relax

\makeatletter
\renewcommand{\printtoctitle}[1]{\centering\HUGE\textit{Contents}}

% Chapter
\usepackage{fmtcount}
\renewcommand{\thechapter}{\Numberstring{chapter}}
\renewcommand{\cftchapterleader}{}
\renewcommand{\cftchapterfillnum}[1]{\hspace*{10pt}\huge#1\cftparfillskip\par}
\renewcommand*{\cftchapterfont}{}
\renewcommand\chapternumberline[1]{\hfil\Large\emph{#1}\hfil\strut\huge\par\nopagebreak\hfil}

% Part
\renewcommand{\cftpartleader}{\hfil\hfil} % <=== insert \hfil\hfil
\renewcommand*{\cftpartfont}{}%
\renewcommand\partnumberline[1]{\hfil\huge\scshape Part #1: } % <=== insert \hfil
\renewcommand*{\cftpartformatpnum}[1]{}%
\renewcommand{\thepart}{\Numberstring{part}}

% Spacing
\setlength{\cftbeforechapterskip}{0pt}
\setlength{\cftbeforepartskip}{50pt}

% Document
\begin{document}
\tableofcontents*
\chapter*[Introduction]{Introduction}
\part{The First Part}
\chapter{The First Chapter}
\end{document}

相关内容