2

Working on a project, I have a multiple page long ToC.

I have formated my chapter level as this :

\titlecontents{chapter}
              [0em]
              {\fontsize{13}{12}\selectfont \filcenter \addvspace{12pt}}%
              {\qquad \fontsize{10}{12}\selectfont Partie \enspace\thecontentslabel \\[-1.5ex] 
              \centerline{\rule{\linewidth}{.5pt}}\vspace{2mm}\\ \qquad}%
              {1em}%
              {}%

Here is the result : enter image description here

Here is the problem: at the end of a page or a column, sometimes the title is split: "Partie" and the ruler on one page, the title on the next one.

How can I avoid this? I have tried \\* and \nobreak, without success...

Bonus question: it does not look perfectly centred, does someone know why?

PS : sorry about \fontsize{13}{12} it looks horrible ! My mistake here, but strangely it works.

MWE :

\documentclass[12pt,twoside]{book}
\usepackage[paperheight=240mm,paperwidth=160mm, left=22mm, right = 20mm, top = 20mm, bottom = 22mm]{geometry}

\usepackage[cam,width=17.5truecm,height=25.54truecm,center,dvips,noinfo]{crop}
\usepackage[french]{babel}



\usepackage{fontspec}

\usepackage{lipsum}
\usepackage[newparttoc]{titlesec}%
\usepackage{titletoc}


% ToC


\usepackage{tocloft}

\usepackage[toc]{multitoc}

\renewcommand*{\multicolumntoc}{2}

\makeatletter
\addto\captionsfrench{\renewcommand\contentsname{\vspace{-2.04cm}\parbox{\linewidth}{\fontsize{18}{12}\selectfont \centerline{TABLE ANALYTIQUE}~\\[-0.5cm]\centerline{\fontsize{7}{12}\selectfont \itshape{Les chiffres renvoient aux num\'eros de pages}}}}}
\makeatother


% Little hack for the end of the ToC : I don't want it to be on both left and right columns but left then right.
\makeatletter
\renewcommand*{\@starttoc}[1]{%
   \ifthenelse{\boolean{@multitoc@toc}\and\equal{#1}{toc}}{%
      \begin{multicols*}{\multicolumntoc}%
         \@multitoc@starttoc{#1}%
      \end{multicols*}%
      }{}%
   }
\makeatother

\setlength\cftaftertoctitleskip{22pt}


\setcounter{tocdepth}{9}

\titlecontents{chapter}
              [0em]
              {\fontsize{13}{12}\selectfont \filcenter \addvspace{12pt}}%
              {\qquad \fontsize{10}{12}\selectfont Partie \enspace\thecontentslabel
              \\[-1.5ex]\centerline{\rule{\linewidth}{.5pt}}\vspace{2mm}\\\qquad}%
              {1em}%
              {}%


\begin{document}

\paragraph{Test}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}
\chapter{Aides d'etat}

\newpage
\tableofcontents

\end{document}
2
  • Commands \frutB and \frutL are not defined in your MWE. Jun 3, 2020 at 19:38
  • @muzimuzhiZ, oups, sorry about this, it is edited. It is only font commands :)
    – Guliup
    Jun 4, 2020 at 7:10

1 Answer 1

3
+50

Your problem is that the parameter \qquad...\qquad is processed in horizontal mode and \vspace behaves like \vadjust{<space>}, so it does not leave the horizontal mode. We use only third parameter of the \titlecontents which is processed in vertical mode. Next parameters are empty.

\titlecontents{chapter}[0em]
     {\fontsize{13}{15}\selectfont \addvspace{12pt}% your settings
      \leftskip=0pt plus1fill \rightskip=\leftskip % centering the paragraph
      \emergencystretch=40pt % narrow columns  
      \let\rightskip=\abovedisplayskip % trick: we don't want to re-declare \rightskip
      \centerline{\fontsize{10}{12}\selectfont Partie \enspace\thecontentslabel}
      % your title at center
      \nobreak\smallskip\hrule height.5pt \nobreak\medskip % rule + unreakable spaces 
     }
     {}{}
     {}
2
  • Thanks a lot, that is perfect !
    – Guliup
    Jun 4, 2020 at 15:52
  • wipet is back at full strength! :-)
    – Malipivo
    Jun 8, 2020 at 5:05

You must log in to answer this question.

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