0

I'm trying to format my table of contents to use two-line, centered entries with ordinal numbers for part and chapter numbers. The entries should also be hyperlinks. I have managed to string together an answer by Simon Dispa that edits the chapters with an altogether different one by daleif that edits the parts to achieve something that looks pretty nice, but lacks the ordinal part numbers and the hyperlinks. Also, it would be nice to get rid of the page numbers for the parts.

When I try to use fmtcount's \Ordinalstringnum in the redefinition of \partnumberline, I get an error. And when I load hyperref the formatting of the part entries fall apart.

Output Output

\documentclass[oneside,11pt]{memoir}

\usepackage{fmtcount} % \usepackage{hyperref}% Messes up the formatting

\renewcommand{\cftchapterfont}{} \renewcommand{\cftchapterpagefont}{\cftchapterfont} \renewcommand{\cftchapteraftersnum}{\ } \renewcommand{\cftchapteraftersnumb}{\newline\normalfont} \renewcommand{\cftchapterleader}{} \renewcommand{\cftchapterafterpnum}{\cftparfillskip} \renewcommand{\cftchapterleader}{\space—\space} \renewcommand{\cftchapterfillnum}[1]{% {\cftchapterleader}\nobreak% {#1}% \cftchapterafterpnum\par% } \makeatletter \renewcommand*{\l@chapapp}[3]{% \ifnum \c@tocdepth >\m@ne \cftchapterbreak \vskip\cftbeforechapterskip% \centering% {\memRTLrightskip0pt% @afterindenttrue% \interlinepenalty@M% \leavevmode% \let@cftbsnum\cftchapterpresnum \let@cftasnum\cftchapteraftersnum% \let@cftasnumb\cftchapteraftersnumb% \def@chapapp@head{}% {\cftchapterfont#1}\nobreak% \cftchapterfillnum{#2}}% \fi} \renewcommand{\chapternumberline}[1]{% \chapternumberlinehook{#1}% \hb@xt@@tempdima{\hfil@chapapp@head@cftbsnum {\itshape\MakeLowercase{\Ordinalstringnum{#1} chapter}}@cftasnum\hfil}% @cftasnumb} \makeatother

\makeatletter \renewcommand{\cftpartleader}{\space—\space} \renewcommand{\cftpartfillnum}[1]{% {\cftpartleader}\nobreak% {#1}% \cftpartafterpnum\par% } \setlength{\cftpartnumwidth}{0em} \setlength{\cftpartindent}{0em} \renewcommand\partnumberline[1]{% \centering \normalsize\bfseries Part~#1 \normalfont\bfseries \par } \renewcommand*{\cftpartformatpnum}[1]{\enspace\textperiodcentered\enspace#1}

\usepackage{etoolbox} % patch \l@part to remove some grouping

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

\begin{document} \frontmatter \tableofcontents* \chapter{Introduction} \chapter{Preface}

\mainmatter \part{The Beginning} \chapter{Where It All Began} \chapter{Some More Beginning}

\part{The Climax} \chapter{Some Drawn-Out Diatribe}

\part{The End} \chapter{Starting to Wrap Up} \chapter{The Insightful Conclusion}

\backmatter \chapter{Some notes} \end{document}

Desired output Desired output

Fredrik P
  • 1,386
  • Do you mind explaining exactly what the expected output it? Preferably with a drawing/image. – daleif Aug 08 '23 at 11:49
  • @daleif I’ll be sure to do that as soon as I’m back at my computer. Back the essence of it is this: I’d like for “Part I” to read “First part”, “Part II” “Second part”, etc. And I’d like to remove the dash and page number from each part title row. – Fredrik P Aug 08 '23 at 12:12
  • 1
    For parts \Ordinalstringnum fails as the arg is not a number it is a roman numerial – daleif Aug 08 '23 at 12:19
  • @daleif That seems reasonable :-D I have updated the question with an image of the desired output – Fredrik P Aug 08 '23 at 13:14
  • 1
    My answer does seem to do that and works with hyperref – daleif Aug 08 '23 at 14:01

1 Answers1

1

This seems to do the part stuff as I understand the question, had to make my own Roman to text as fmtcounter expects a number not a letter.

(edit: simpler helper)

\ExplSyntaxOn
\NewDocumentCommand\RomanToText{m}{\Ordinalstringnum{\int_from_roman:n {#1}}}
\ExplSyntaxOff

\makeatletter \renewcommand\partnumberline[1]{\RomanToText{#1}~part\par} \renewcommand\cftpartfont{\par\centering}% the starting \par is needed \cftpagenumbersoff{part}

\usepackage{etoolbox}

\patchcmd\l@part{% \cftpartfont {#1}% }{% \cftpartfont #1\par% }{\typeout{l@part patched}}{\typeout{l@part patch failed}} \makeatother

daleif
  • 54,450
  • A minor improvement would be to patch to \ctfpartfont {#1}\par% instead to retain the possibility that the very last element \ctfpartfont may be a macro that takes one argument. – Fredrik P Aug 08 '23 at 14:11
  • Also if it is not necessary that parts should elsewhere be numbered using roman numerals, one could do \renewcommand{\thepart}{\arabic{part}} and then just change \RomanToText{#1} to \Ordinalstringnum{#1} – Fredrik P Aug 08 '23 at 14:13