2

I need to change \thechapter into something that spans several characters. Doing so mixes up characters in my customized table of contents (as well as the ordinary ToC). Here's an example:

ToC

Here's an MWE:

\documentclass{book}
\usepackage{titlesec}
\usepackage{titletoc}

\titleformat{\chapter}{\huge\bfseries}{\chaptertitlename~\thechapter.}{1ex}{\huge}
  [%
   \vspace*{1em}
   \startcontents
   \normalfont\normalsize\printcontents{}{0}{\setcounter{tocdepth}{1}}%
  ]

\begin{document}

\renewcommand\thechapter{abcdef}

\chapter{Intro}
\section{Preliminaries}
\section{Goals}
\section{Formulas}
\end{document} 

How can I increase the space reserved for section counter in the ToC, so that it does not clash into the section name?

Sadeq Dousti
  • 4,380

1 Answers1

2

You need to adjust the contents-related entry associated with \section and increase in the label width. Do so using titletoc's \dottedcontents:

enter image description here

\documentclass{book}
\usepackage{titlesec,titletoc}

\titleformat{\chapter}{\huge\bfseries}{\chaptertitlename~\thechapter.}{1ex}{\huge}
  [%
   \vspace*{1em}
   \startcontents
   \normalfont\normalsize\printcontents{}{0}{\setcounter{tocdepth}{1}}%
  ]

\dottedcontents{section}% <section>
  [5em]% <left>
  {}% <above code>
  {5em}% <label width>
  {1pc}% <leader width>

\begin{document}

\renewcommand\thechapter{abcdef}

\chapter{Intro}
\section{Preliminaries}
\section{Goals}
\section{Formulas}

\end{document}

Above I've set <left> to 5em, meaning the \section titles in the ToC will start 5em from the left margin. Additionally, the <label width> is also set to 5em, meaning the labels will start flush (left) with the margin.

Werner
  • 603,163