TransWikia.com

How to align non-numbered and numbered chapters in memoir with non-standard spacing?

TeX - LaTeX Asked by Roxy on April 30, 2021

I have a memoir document with custom TOC spacing:

documentclass[oneside]{memoir}

renewcommand{cftchapteraftersnum} {quad}
renewcommand{cftchapterdotsep}    {cftsectiondotsep}
renewcommand{cftchapterfont}      {cftsectionfont}
renewcommand{cftchapterleader}    {cftsectionleader}
renewcommand{cftchapterpagefont}  {cftsectionpagefont}
renewcommand{cftchapterpresnum}   {hfill}
setlength   {cftbeforechapterskip}{0.5em}
setlength   {cftchapternumwidth}  {10em}

begin{document}
frontmatter

chapter{Preface}
tableofcontents*

mainmatter
chapter{Alpha}
chapter{Beta}
end{document}

This generates a TOC like this:

enter image description here

I cannot find any memoir options to give non-numbered entries a space at the beginning so that I can line up the Preface entry with the numbered chapter names (i.e. Preface left-aligned with Alpha). Any way to do this?

One Answer

Add the following lines after loading the memoir class.

usepackage{xpatch}
makeatletter
xpatchcmd@chapter
  {addcontentsline{toc}{chapter}{f@rtoc}}%
  {addcontentsline{toc}{chapter}{protectchapternumberline{}f@rtoc}}%
  {}%
  {}
makeatother

This will handle only the preface. chapter* headings in the main part are handled differently. For these, it is sufficient to add the line

renewcommandmemchapstarinfo[2]{addcontentsline{toc}{chapter}{protectchapternumberline{}#1}}

enter image description here

documentclass[oneside]{memoir}
usepackage{xpatch}
makeatletter
xpatchcmd@chapter
  {addcontentsline{toc}{chapter}{f@rtoc}}%
  {addcontentsline{toc}{chapter}{protectchapternumberline{}f@rtoc}}%
  {}%
  {}
makeatother
renewcommandmemchapstarinfo[2]{addcontentsline{toc}{chapter}{protectchapternumberline{}#1}}  
renewcommand{cftchapteraftersnum} {quad}
renewcommand{cftchapterdotsep}    {cftsectiondotsep}
renewcommand{cftchapterfont}      {cftsectionfont}
renewcommand{cftchapterleader}    {cftsectionleader}
renewcommand{cftchapterpagefont}  {cftsectionpagefont}
renewcommand{cftchapterpresnum}   {hfill}
setlength   {cftbeforechapterskip}{0.5em}
setlength   {cftchapternumwidth}  {10em}

begin{document}
frontmatter
chapter{Preface}
tableofcontents*

mainmatter
chapter{Alpha}
section{Alpha 1}
section{Alpha 2}
chapter*{Beta}
section{Beta 1}
section{Beta 2}
end{document}

Correct answer by gernot on April 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP