I'm using tocloft
and would like to produce a two-column table of contents. While it's easy to just wrap the whole toc in a multicol
-environment, I don't like the look of that, because the title gets wrapped into that as well, which makes the second column start above the title.
As tocloft
redefines \tableofcontents
using \AtBeginDocument
, I thought instead of overwriting that definition at a later point I might just redefine \@starttoc
to produce what I want, like this:
\documentclass{scrbook}
\usepackage{multicol}
\usepackage{tocloft}
\makeatletter
% tocloft redefines \tableofcontents \AtBeginDocument
% As I don't want the title to be part of the two column layout,
% it seems easiest to just add the multicols to \@starttoc.
\let\@starttocorg\@starttoc
\def\@starttoc#1{%
\begin{multicols*}{2}%
\@starttocorg{#1}%
\end{multicols*}}%
\makeatother
\begin{document}
\tableofcontents
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\end{document}
Which produces:
But as I don't know what \@starttoc
does internally, I'm not sure if it's safe to do that. Are there any implications I don't see? (I suppose I could also re-phrase the question as Can it really be that easy?)
Best Answer
Each of the KOMA-Script classes
scrartcl
,scrreprt
andscrbook
load and use packagetocbasic
for the ToC and the Lists.tocbasic
uses\tocbasic@starttoc
based on\@starttoc
.\tocbasic@starttoc
and\@starttoc
both are internal commands and should not be redefined by users. Buttocbasic
provides two hooks to execute code before (\BeforeStartingTOC
) and after (\AfterStartingTOC
)@starttoc
.Note that
\BeforeStartingTOC
and\AfterStartingTOC
are at the same group level (inside the same group), so you can use:Code:
Or with the starred version of
multicols
: