1

I'm typesetting a book with memoir class and in this book the parts have to be centred in the table of contents (TOC). Thanks to Center parts in toc with tocloft I got this working as long as the part name isn't longer than one line. But if it is longer, the second line is not centred. Here is a working example:

\documentclass[a4paper,10pt,twoside]{memoir}

\usepackage{polyglossia} 
\usepackage{blindtext}
\usepackage{fontspec}

\makeatletter
\renewcommand{\partnumberline}[1]{\hfil\hspace\@tocrmarg Teil #1:~}
\makeatother
\renewcommand{\cftpartfont}{\large\normalfont}
\cftpagenumbersoff{part}

\begin{document}
\tableofcontents*
\part{It works with one liners}
\chapter{Test}
\Blindtext
\section{Test124}
\Blindtext
\part{But it does not work with those: That is only a test nothing more, please do not read it}
\chapter{Test2}
\Blindtext \Blindtext \Blindtext
\end{document}

enter image description here

What could I do to get all lines centred?

3

The easiest solution might be to not use the memoir interface at all!

Instead go straight to the source and recode it. Here I have removed all the code that normally makes space for the page number and the left indentation etc.

\makeatletter
\renewcommand{\partnumberline}[1]{Teil #1:~}
\renewcommand*{\l@part}[2]{%
  \ifnum \c@tocdepth >-2\relax
    \cftpartbreak
    \begingroup
      {
        \setlength{\memRTLleftskip}{0pt}
        \setlength{\memRTLrightskip}{0pt}
        \interlinepenalty\@M
        \centering
        \cftpartfont #1
        \par
      }
      \nobreak
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\makeatother
\renewcommand{\cftpartfont}{\large\normalfont}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.