3

based on this post I was able to customize the appearence of my table of contents. I am very pleased with the result exept for one small detail: The spacing between the ToC-entries.

The table of content as it is with the (new) example code. The distance indicated by the red arrow should be reduced, while not touching the other distances (i.e., blue boxes).

I would like the entries to be closer together. A solution for standard chapters/parts etc. is something like \setlength{\cftbeforeXskip} (probably more like \cftafterXskip, to keep the spacing to previous entries?), but I don't quite understand how to apply this command to the new sectionstyle (chapterstar).

Thank you for your help!

MWE:

\documentclass[12pt,a4paper,ngerman]{scrbook}

\usepackage[titles]{tocloft}
\usepackage{etoolbox}
\makeatletter
\let\l@chapterstar\l@chapter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}% Insert starred chapter font
\patchcmd{\l@chapterstar}{#2}{\cftchapstarpagefont #2}{}{}% Insert starred chapter page number font

\makeatother
\newcommand{\cftchapstarfont}{\cftchapfont\normalsize}
\newcommand{\cftchapstarpagefont}{\cftsecpagefont\normalsize}

%%%%%%%%%%%%%%%%%%%%% START BODY
\begin{document}
\tableofcontents

\chapter{Full Chapter 1}
\section{Section 1}
\section{Section 2}
\chapter{Full Chapter 2}

\addcontentsline{toc}{chapterstar}{StarChap1}
\chapter*{StarChap1}

\addcontentsline{toc}{chapterstar}{StarChap2}
\chapter*{StarChap2}

\end{document}

Edit: Thank you for improving the post, I thought I was posting within the specific Latex Stack-exchange.

Edit 2: I have updated the code (and image) to be a little more complex. As I have normal parts, chapters and subsections in my original document, but I just want to decrese the distance for the chapterstar entries, while keeping the other distances (such as the blue boxes) unchanged.

Pettersson
  • 43
  • 6

1 Answers1

1

\setlength{\cftbeforechapskip}{.1ex} seems to also work for your custom chapters:

\documentclass[12pt,a4paper,ngerman]{scrbook}

\usepackage[titles]{tocloft}
\usepackage{etoolbox}
\makeatletter
\let\l@chapterstar\l@chapter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}% Insert starred chapter font
\patchcmd{\l@chapterstar}{#2}{\cftchapstarpagefont #2}{}{}% Insert starred chapter page number font

\apptocmd{\l@chapterstar}{\setlength{\cftbeforechapskip}{.1ex}}{}{}

\makeatother
\newcommand{\cftchapstarfont}{\cftchapfont\normalsize}
\newcommand{\cftchapstarpagefont}{\cftsecpagefont\normalsize}

%%%%%%%%%%%%%%%%%%%%% START BODY
\begin{document}
\tableofcontents

\chapter{Full Chapter 1}
\section{Section 1}
\section{Section 2}
\chapter{Full Chapter 2}

\addcontentsline{toc}{chapterstar}{StarChap1}
\chapter*{StarChap1}

\addcontentsline{toc}{chapterstar}{StarChap2}
\chapter*{StarChap2}

\end{document}

enter image description here

  • Hello samcarter_is_at_topanswers.xyz thank you for your input! I believe the way it is right now, the chapterstar inherits the settings from the chapter class, that's why it reacts on the change. However, in my original document there are also Parts, Chapters and Sections. These entries should not be touched from the setting. With your solution all chapter entries will also move together. I have updated the example from the original post accordingly, to clarify. – Pettersson Aug 01 '22 at 22:09
  • @Pettersson See my edit. If you don't want it to effect the previous "normal" chapters, you could either manually place it in the code at an appropriate place or add it to your star chapter – samcarter_is_at_topanswers.xyz Aug 02 '22 at 11:40
  • This does exactly what I wished for! Thank you for your effort! – Pettersson Aug 02 '22 at 13:41