TeX - LaTeX Asked by kgrady on July 1, 2021
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:
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]{centeringLargetextit{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}{normalsizescshape}%
renewcommand*{cftpartaftersnum}{}%
renewcommand*{cftpartaftersnumb}{}%
renewcommand*{cftpartformatpnum}[1]{%
cftpartformatpnumhook{#1}%
hbox to @pnumwidth{enspacetextperiodcenteredenspace{cftpartpagefont #1}hfil}}%
renewcommand{cftpartafterpnum}{cftparfillskip}%
longdef@part[#1]#2{%
M@gettitle{#1}%
deff@rtoc{hfilbfseries{#1}}
@nameuse{part@f@rtoc@before@write@hook}%
phantomsection
mempreaddparttotochook
ifnum c@secnumdepth >-2relax
refstepcounter{part}%
addcontentsline{toc}{part}%
{protectpartnumberline{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
parskipz@
normalfont
ifnum c@secnumdepth >-2relax
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:
(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.
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]{centeringLargetextit{textbf{Contents}}}
setpnumwidth{2em}
setrmarg{4em}
setlength{cftpartnumwidth}{0em}
setlength{cftpartindent}{0em}
setlength{cftbeforepartskip}{12pt}
renewcommand{cftpartleader}{}
renewcommand*{cftpartfont}{}%
% debox partnumberline
renewcommandpartnumberline[1]{%
centering
normalsizescshape Part~#1:
normalfontbfseries
par
}
renewcommand*{cftpartformatpnum}[1]{enspacetextperiodcenteredenspace#1}
usepackage{etoolbox}
% patch l@part to remove some grouping
patchcmdl@part{%
{cftpartfont {#1}}cftpartfillnum{#2}%
}{%
#1cftpartfillnum{#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}
Correct answer by daleif on July 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP