1

When I use the command \numberwithin{section}{part} the table of contents formatting gets destroyed.

A minimal working example is the following:

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{amsmath} \numberwithin{section}{part}

\begin{document}

\tableofcontents{}

\newpage

\part{First PArt} \section{First Section} \section{Next Section} \subsection{abc} \subsection{ABC}

\part{Second PArt} \section{The third Section} \section{And another Section} \subsection{This is an example} \subsection{Example ;-)}

\part{Third Part} \section{Wrong formatting} \section{Another Section} \section{Test Section} \subsection{xyz} \subsection{XYZ}

\end{document}

This yields the following table of contents: (I compile with Lualatex, if that is relevant) enter image description here

As one can see the space between the numbering and the title of the sections is wrong and in case of Part 3 even overlaps.

How can I fix this?

Sinthoras
  • 57
  • 3

2 Answers2

1

You can use (without \numberwithin{section}{part})

\RedeclareSectionCommand[tocdynnumwidth]{part}
\RedeclareSectionCommand[counterwithin=part,tocdynnumwidth]{section}
\RedeclareSectionCommands[tocdynnumwidth,tocdynindent]
  {subsection,subsubsection,paragraph,subparagraph}

Example:

\documentclass[a4paper,12pt]{scrartcl}
\RedeclareSectionCommand[tocdynnumwidth]{part}
\RedeclareSectionCommand[counterwithin=part,tocdynnumwidth]{section}
\RedeclareSectionCommands[tocdynnumwidth,tocdynindent]
  {subsection,subsubsection,paragraph,subparagraph}

\begin{document} \tableofcontents{} \clearpage

\part{First PArt} \section{First Section} \section{Next Section} \subsection{abc} \subsection{ABC}

\part{Second PArt} \section{The third Section} \section{And another Section} \subsection{This is an example} \subsection{Example ;-)}

\part{Third Part} \section{Wrong formatting} \section{Another Section} \section{Test Section} \subsection{xyz} \subsection{XYZ} \end{document}

Run three times to get

enter image description here

esdd
  • 85,675
1

Use the tocloft package.

...

\usepackage{tocloft} \addtolength{\cftsecnumwidth}{2em} % or other length

which will increase the space for the section number.

Peter Wilson
  • 28,066