0

Referring to this thread: Handle part (book class) with titletoc , I've a new file, this time compiled with XeLaTeX (and no more with pdfLaTeX).

If I use the same code for titletoc, section titles are no more correctly aligned, I mean centered. It's very evident in the first part title, as you can see in the under picture:

enter image description here

The code:

\documentclass[a4paper,11pt]{book}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{titlesec,titletoc}
\usepackage{etoolbox}

\setmainfont{EB Garamond}
\setmainlanguage[babelshorthands=true]{italian}
\PolyglossiaSetup{italian}{indentfirst=false}
\frenchspacing

\makeatletter
\patchcmd\@part
  {\thepart}
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

\makeatletter
\contentsmargin[-1.55em]{1.55em}

\titlecontents{part}
  [0em]
  {\addvspace{1.5pc}\filcenter}
  {\large\partname~\thecontentslabel\endgraf\bfseries}
  {\large}
  {}
  [\addvspace{.5pc}]

\titlecontents{chapter}
  [4em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {\hspace*{0.5em}}
  {}
  []

\titlecontents{section}
  [4em]
  {\vspace*{.2\baselineskip}\mdseries\small}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {}
  {\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\makebox[1pc][r]{\thecontentspage}}}}
  []

\titlecontents*{subsection}
  [4.525em]
  {\footnotesize}
  {}
  {}
  {, \thecontentspage}
  [~--~]
  []
\makeatletter\@addtoreset{chapter}{part}\makeatother

\begin{document}

\tableofcontents

\part{Title}

\chapter{First Chapter}

\chapter{Second Chapter}

\part{Long Title of the Second Part}

\chapter{First Chapter}

\chapter{Second Chapter}

\part{Very Long Title of the Third Part}

\chapter{First Chapter}

\chapter{Second Chapter}

\end{document}

What could be the cause of the problem? Thanks!

1

The book code inserts a \hspace that you should remove too. Be aware that EB Garamond has not bold version and so the \bfseries has no effect.

\documentclass[a4paper,11pt]{book}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{titlesec,titletoc}
\usepackage{etoolbox}

\setmainfont{EB Garamond}
\setmainlanguage[babelshorthands=true]{italian}
\PolyglossiaSetup{italian}{indentfirst=false}
\frenchspacing

\makeatletter
\patchcmd\@part
  {\thepart\hspace{1em}} %<----------
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

\makeatletter
%\contentsmargin[-1.55em]{1.55em}

\titlecontents{part}
  [0em]
  {\addvspace{1.5pc}\filcenter}
  {\large\partname~\thecontentslabel\endgraf\bfseries}
  {\large}
  {}
  [\addvspace{.5pc}]

\titlecontents{chapter}
  [4em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {\hspace*{0.5em}}
  {}
  []

\titlecontents{section}
  [4em]
  {\vspace*{.2\baselineskip}\mdseries\small}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {}
  {\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\makebox[1pc][r]{\thecontentspage}}}}
  []

\titlecontents*{subsection}
  [4.525em]
  {\footnotesize}
  {}
  {}
  {, \thecontentspage}
  [~--~]
  []
\makeatletter\@addtoreset{chapter}{part}\makeatother

\begin{document}

\tableofcontents

\part{Title}

\chapter{First Chapter}

\chapter{Second Chapter}

\part{Long Title of the Second Part}

\chapter{First Chapter}

\chapter{Second Chapter}

\part{Very Long Title of the Third Part}

\chapter{First Chapter}

\chapter{Second Chapter}

\end{document}

enter image description here

  • Thanx, now it looks perfect. PS This EB Garamond by Pardo has bold (and bold italic) version too: link; I use it in my real file – user41063 Nov 15 '18 at 23:40
  • Both solutions work fine, I'm not able to say what's the best one. In any case, why in standard classes \part is handeled in a non-standard way? is there anything that could (and should) be reviewed or corrected by programmers? – user41063 Nov 16 '18 at 14:34
1

Due to the non-standard way \part is handeled in standard classes, you have to load titlesec with option newparttoc and re-define the layout of \part with `\titleformat è . So I propose this code:

\documentclass[a4paper,11pt]{book}
\usepackage[showframe]{geometry}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}

\setmainfont{EB Garamond}
\setmainlanguage[babelshorthands=true]{italian}
\PolyglossiaSetup{italian}{indentfirst=false}
\frenchspacing

%\makeatletter
%\patchcmd\@part
% {\thepart}
% {\protect\numberline{\thepart}}
% {}{\FAIL}
%\makeatother
%
\titleformat{\part}[display]{\bfseries\filcenter}{\partname~\thepart}{5ex}{\Huge}

\makeatletter
\contentsmargin[-1.55em]{1.55em}
 \titlecontents{part}
 [0em]
 {\addvspace{1.5pc}\filcenter\large}
 {\makebox[\linewidth]{\partname~\thecontentslabel}\endgraf\bfseries\makebox[\linewidth]}
 {\large}
 {}
 [\addvspace{.5pc}]
\titlecontents{chapter}
  [4em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {\hspace*{0.5em}}
  {}
  []

\titlecontents{section}
  [4em]
  {\vspace*{.2\baselineskip}\mdseries\small}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {}
  {\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\makebox[1pc][r]{\thecontentspage}}}}
  []

\titlecontents*{subsection}
  [4.525em]
  {\footnotesize}
  {}
  {}
  {, \thecontentspage}
  [~--~]
  []
\makeatletter\@addtoreset{chapter}{part}\makeatother

\begin{document}

\tableofcontents

\part{Title}

\chapter{First Chapter}

\chapter{Second Chapter}

\part{Long Title of the Second Part}

\chapter{First Chapter}

\chapter{Second Chapter}

\part{Very Long Title of the Third Part}

\chapter{First Chapter}

\chapter{Second Chapter}

\end{document} 

enter image description here

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.