3

I want to set the space between the part number and the part title to a specific length, so that the horizontal space between them is always the same.

I found a solution for the memoir-class,

Adding space in ToC between the part number and part title

but this doesn't work with scrreprt.

I know that i can increase the tocnumwidth, but that results to different space width with parts numbered Roman.

Here is my MWE with the result:

\documentclass[openany,12pt]{scrreprt}

%-------Allgemeine Einstellungen--------------------
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

%------Verzeichnisse------------
\setcounter{tocdepth}{5} % fünf Ebenen statt drei im Inhaltsverzeichnis anzeigen
\setcounter{secnumdepth}{5} % fünf Ebenen sollen nummeriert werden

\usepackage{chngcntr}
\counterwithin*{chapter}{part}

%-------Verlinkungen-------
\usepackage[colorlinks]{hyperref} % Inhaltsverzeichnis anklickbar

\begin{document}

\clearpage
\pagenumbering{Roman} % römische Zahlen für Inhaltsverzeichnis etc.
\setcounter{page}{1} 
%----------Inhaltsverzeichnis
\tableofcontents

\pagenumbering{arabic} % Arabische Zahlen für den Inhalt

\part{Erster Teil}

\chapter{Erstes Kapitel}

\part{Zweiter Teil}

\chapter{Noch nen Kaptiel}

\part{Dritter Teil}

\chapter{Noch so ein Kaptiel}

\end{document}

The Blue marked space should have the same width. Blue marked space should have the same width

1
  • Unrelated: You should load hyperref as the last package and you should not load it twice ;-) If you would not use KOMA, the solution is to use tocloft for the spacings in the TOC, but that package and KOMA do not like each other really. – user31729 Mar 13 '17 at 20:08
2

KOMA defines sectioning commands by \DeclareSectionCommand. The default definition of part is

\DeclareSectionCommand[%
  style=part,%
  level=\m@ne,%
  pagestyle=plain,%
  tocstyle=part,%
  toclevel=\m@ne,%
  tocindent=\z@,%
  tocnumwidth=2em%
]{part}

However based on the documentation you have to change the length of tocnumwidth. This can be done by \RedeclareSectionCommand. However you have to subtract the width of the part number:

\documentclass[openany,12pt]{scrreprt}
\makeatletter
\newlength\parttocspacetemplength
 \newcommand\parttocspaceI[1]{%
   \sbox\@tempboxa{{#1}}%
   \setlength{\global\parttocspacetemplength}{\wd\@tempboxa}%
    \usebox\@tempboxa%
    } 

 \RedeclareSectionCommand[%
   tocentrynumberformat=\parttocspaceI,
   tocnumwidth=\dimexpr3em+\parttocspacetemplength\relax,%
 ]{part}
\makeatother

%-------Allgemeine Einstellungen--------------------
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

%------Verzeichnisse------------
\setcounter{tocdepth}{5} % fünf Ebenen statt drei im Inhaltsverzeichnis anzeigen
\setcounter{secnumdepth}{5} % fünf Ebenen sollen nummeriert werden

\usepackage{chngcntr}
\counterwithin*{chapter}{part}

%-------Verlinkungen-------
\usepackage[colorlinks]{hyperref} % Inhaltsverzeichnis anklickbar

\begin{document}

\clearpage
\pagenumbering{Roman} % römische Zahlen für Inhaltsverzeichnis etc.
\setcounter{page}{1} 
%----------Inhaltsverzeichnis
\tableofcontents

\pagenumbering{arabic} % Arabische Zahlen für den Inhalt

\part{Erster Teil}

\chapter{Erstes Kapitel}

\part{Zweiter Teil}

\chapter{Noch nen Kaptiel}

\part{Dritter Teil}

\chapter{Noch so ein Kaptiel}

\end{document}

enter image description here

3
  • What you explain, only increases the tocnumwidth = width of number + space, but it results to differnt size of space between the part number and title. – duichwer Mar 13 '17 at 21:06
  • @duichwer: I haven't read the question well. Sorry. Now it should work – Marco Daniel Mar 13 '17 at 22:13
  • I do not understands how this new box for the part there works, but it works :) – duichwer Mar 13 '17 at 22:47
1

Another possibility is patching \addparttocentry:

\usepackage{xpatch}
\xpatchcmd\addparttocentry
  {\addtocentrydefault{part}{#1}{#2}}
  {\ifstr{#1}{}
    {\addtocentrydefault{part}{#1}{#2}}%
    {\addtocentrydefault{part}{}{\texorpdfstring{#1\autodot\enskip}{}#2}}%
  }
  {}{\PatchFailed}
\RedeclareSectionCommand[
  tocnumwidth=0pt
]{part}

Note that \pagenumbering resets the page number to 1. If you use this command inside the document, insert \cleardoubleoddpage before it. Then the new page numbering starts on a new right page. (In your MWE it starts on the last page of TOC.)

Additionally use \counterwithin after package hyperref is loaded. (In your MWE all chapter entries in TOC are linked to "Erstes Kapitel".)

\documentclass[%
  %open=any,% default for scrreprt and not needed for an onesided document
  12pt
]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}

\usepackage{chngcntr}

\usepackage{xpatch}
\xpatchcmd\addparttocentry
  {\addtocentrydefault{part}{#1}{#2}}
  {\ifstr{#1}{}
    {\addtocentrydefault{part}{#1}{#2}}%
    {\addtocentrydefault{part}{}{\texorpdfstring{#1\autodot\enskip}{}#2}}%
  }
  {}{\PatchFailed}
\RedeclareSectionCommand[
  tocnumwidth=0pt
]{part}

\usepackage[colorlinks]{hyperref}
\counterwithin*{chapter}{part}% <- after hyperref is loaded

\begin{document}
%\cleardoubleoddpage% <- if there are pages before the Roman numbering
\pagenumbering{Roman}% <- resets the pagenumber to 1
\tableofcontents

\cleardoubleoddpage% <- added to ensure that the changed pagenumbering starts on a new right page
\pagenumbering{arabic}
\part{Erster Teil}
\chapter{Erstes Kapitel}

\part{Zweiter Teil}
\chapter{Noch nen Kapitel}

\part{Dritter Teil}
\chapter{Noch so ein Kapitel}

\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.