0

Preliminaries: I have read through the memoir manual section on ToC many times. While I was able to get many things I wanted done, I was not able to fix the last piece.

I also have consulted prior questions/answers (and there are several on trying to get \part entries formatted in various ways, particularly centered) they have not given me an answer. I do not believe this is a duplicate, despite question title similarity. The other questions/answers include: Centering part entries in toc using memoir, How can I properly center my table of contents?, Customize TOC, center align and italics in memoir, How to center part entries in toc with memoir?, and Memoir: Part contents in TOC in two lines.

The issue: Each part entry should be centered under the ToC heading ("Contents" in bold + italics). I can't get the entries centered.

Each part entry includes the prefix "Part", the part number, a colon, a line break, the title of the part, a space, a centered period, a space, the page number. The word "Part" should be in small caps and the "Part"/space/part number/colon should be in normal font. The part title/centered period/page number should be in boldface. The part title may be multiline. The following image shows the desired end state: enter image description here

The MWE: This is my current working MWE:

\documentclass[smallroyalvopaper,11pt,twoside]{memoir}

\title{\HUGE{\textbf{Name of Book} \\ \LARGE{\textit{Subtitle of book}}}}
\author{\Large{Author's Name}}
\date{Date Written}

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

\setpnumwidth{2em}
\setrmarg{4em}
\setlength{\cftpartnumwidth}{0em}
\setlength{\cftpartindent}{0em}
\setlength{\cftbeforepartskip}{12pt}
\renewcommand{\cftpartleader}{}
\cftsetindents{part}{\cftpartindent}{\@pnumwidth}

\renewcommand*{\cftpartname}{}%
\renewcommand*{\cftpartfont}{\normalsize\scshape}%
\renewcommand*{\cftpartaftersnum}{}%
\renewcommand*{\cftpartaftersnumb}{\\}%

\renewcommand*{\cftpartformatpnum}[1]{%
    \cftpartformatpnumhook{#1}%
    \hbox to \@pnumwidth{\enspace\textperiodcentered\enspace{\cftpartpagefont #1}\hfil}}%
\renewcommand{\cftpartafterpnum}{\cftparfillskip}%

\long\def\@part[#1]#2{%
  \M@gettitle{#1}%
  \def\f@rtoc{\hfil\bfseries{#1}}
  \@nameuse{part@f@rtoc@before@write@hook}%
  \phantomsection
  \mempreaddparttotochook
  \ifnum \c@secnumdepth >-2\relax
    \refstepcounter{part}%
    \addcontentsline{toc}{part}%
      {\protect\partnumberline{\hspace*{5em}\hfil Part~\thepart :\hfil\\}\f@rtoc}%
    \mempartinfo{\thepart}{\f@rtoc}{#2}%
  \else
    \addcontentsline{toc}{part}{\f@rtoc}%
    \mempartinfo{}{\f@rtoc}{#2}%
  \fi
  \mempostaddparttotochook
  \partmark{#1}%
  {\centering
   \interlinepenalty \@M
   \parskip\z@
   \normalfont
   \ifnum \c@secnumdepth >-2\relax
     \printpartname \partnamenum \printpartnum
     \midpartskip
   \fi
   \printparttitle{#2}\par}%
  \@endpart}
\makeatother

\begin{document}
\maketitle
\clearpage
\tableofcontents*
\mainmatter
\part{This is the First Part Heading}
\part{This is the Second Part Heading which is a Long Heading to Check for Wrap Formatting}
\part{This is the Third Part Heading}
\end{document}

I have tried permutations, iterations, and combinations of the answers in the similar questions. Obviously, none of those have worked: the entries do not center. The current MWE produces the following result:

enter image description here

(Note: hspace is set at 5em based on one of the other questions. tocrmarg = 4em plus 1em for the gap memoir inserts between number and title.) As a side note, the ToC format I'm trying to achieve was used by Jacques Barzun in his book, From Dawn to Decadence. Finally, while there may be places where things could be condensed, if condensing doesn't affect the end result it just "cleans up" the code, I would appreciate it if you would refrain from making those changes. Ultimately, this code is part of a larger project that will be used for pedagogical purposes so being able to walk through line-by-line helps.

Thanks for your assistance.

4
  • Unrelated: note that macros like \LARGE does not take arguments. thus after \LARGE{text} the size is still \LARGE.
    – daleif
    Feb 25, 2021 at 17:28
  • Thanks, @daleif. Been through so many edits I missed the stray {}.
    – kgrady
    Feb 25, 2021 at 18:38
  • 1
    To clarify, this was a hack for the MWE. In the "real" doc I use a constructed title page.
    – kgrady
    Feb 25, 2021 at 19:14
  • I would just have left it out to keep the example as small as possible
    – daleif
    Feb 26, 2021 at 7:24

1 Answer 1

1

Here is a possible solution

There are two parts. First we redefine \partnumberline to get rid of the boxing and we'll add a lot of out formatting there. Note that the title part of the toc entry will come as

 \partnumberline{number}Title

Next we patch \l@part to get rid of some grouping.

\documentclass[smallroyalvopaper,11pt,twoside]{memoir}

% formatting really does not belong inside \title and friends /daleif
\title{\HUGE{\textbf{Name of Book} \\ \LARGE{\textit{Subtitle of book}}}}
\author{\Large{Author's Name}}
\date{Date Written}

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

\setpnumwidth{2em}
\setrmarg{4em}
\setlength{\cftpartnumwidth}{0em}
\setlength{\cftpartindent}{0em}
\setlength{\cftbeforepartskip}{12pt}
\renewcommand{\cftpartleader}{}
\renewcommand*{\cftpartfont}{}%
% debox \partnumberline
\renewcommand\partnumberline[1]{%
  \centering
  \normalsize\scshape 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}
\maketitle
\clearpage
\tableofcontents*
\mainmatter
\part{This is the First Part Heading}
\part{This is the Second Part Heading which is a Long Heading to Check for Wrap Formatting}
\part{This is the Third Part Heading}
\end{document}

enter image description here

2
  • Thanks - this works!
    – kgrady
    Feb 25, 2021 at 19:13
  • @kgrady remember to hit the accept mark it it was ok
    – daleif
    Feb 26, 2021 at 7:24

You must log in to answer this question.

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