0

My MWE below centers my TOC the way I'd like except the \usepackage{hyperref} fully justifies the Parts. E.g., "Part One: The First Part" is fully justified:

enter image description here

When I comment out \usepackage{hyperref} the Parts are centered the way I'd like:

enter image description here

How can I have the Parts not fully justified when using 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}
4
  • well the code for the link from hyperref readds the grouping that your patch removed. The best would be if memoir supported hyperref directly, then hyperref wouldn't have to interfere. Commented May 25, 2023 at 7:38
  • Thanks @UlrikeFischer. I didn't realize my patchcmd was causing the issue. I achieved the same effect with some \hfils and will post an answer. Commented May 25, 2023 at 9:08
  • the patchcmd doesn't cause the issue, the new group from hyperref is the problem, your patchcmd is now useless. Commented May 25, 2023 at 9:10
  • @UlrikeFischer I'm not using the patchcmd anymore. Commented May 25, 2023 at 9:37

1 Answer 1

0

As described in the comments, I didn't realize that my patchcmd was the issue. I removed it and achieved the same effect by inserting some \hfils as shown in my updated MWE.

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .