The table of contents in my document looks like this at the moment:
This is exactly how it should look like (with hyperlinks) – there is one problem, though. I only got this restult by using the tocstyle
package, which I would now like to change. Instead, I'd like to have the same result using the tocloft
package, if possible. Here is the code I've used up to now, so this one still contains tocstyle
:
\documentclass[headings=normal, oneside, hidelinks]{scrartcl}
\usepackage{tocstyle}
\usetocstyle{allwithdot}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
%% Distances between number and entry
\settocfeature[toc][1]{spaceafternumber}{15pt}
\settocfeature[toc][2]{spaceafternumber}{15pt}
\settocfeature[toc][3]{spaceafternumber}{12pt}
\settocfeature[toc][4]{spaceafternumber}{12pt}
%% Formatting entries
\usepackage{microtype}
\settocfeature[toc][1]{entryhook}{\MakeHyperLinkStartUppercase\bfseries}
\settocfeature[toc][2]{entryhook}{\MakeHyperLinkStartUppercase}
\settocfeature[toc][3]{entryhook}{\itshape}
\settocfeature[toc][4]{entryhook}{}
%% Entries with uppercase and hyperlinks
\makeatletter
\newcommand*\MakeHyperLinkStartUppercase{%
\let\saved@hyper@linkstart\hyper@linkstart
\def\hyper@linkstart##1##2##3{%
\saved@hyper@linkstart{##1}{##2}{\textls[50]{\MakeUppercase {##3}}}}%
}
\makeatother
\usepackage{hyperref}
\begin{document}
\tableofcontents
\newpage
\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
\end{document}
I've been looking for an alternative solution for a long time, but most suggestions contained the memoir class. However, I was able to use something from this answer here (How to make section name uppercase in ToC?). Here is how far I've gotten, trying to use tocloft
:
\documentclass[headings=normal, oneside, hidelinks]{scrartcl}
\usepackage{tocloft}
\usepackage{textcase}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
%% Distances between dots
\makeatletter
\renewcommand*{\@dotsep}{0.5}
\makeatother
%% Distances between number and entry
\makeatletter
\renewcommand{\l@section}{\vspace{.025\textwidth} \@dottedtocline{1}{20pt}{20pt}}
\renewcommand{\l@subsection}{\@dottedtocline{2}{40pt}{30pt}}
\renewcommand{\l@subsubsection}{\@dottedtocline{3}{70pt}{40pt}}
\renewcommand{\l@paragraph}{\@dottedtocline{4}{110pt}{40pt}}
\usepackage{hyperref}
%% Uppercase and hyperref for sections
\makeatletter
\let\oldcontentsline\contentsline
\def\contentsline#1#2{%
\expandafter\ifx\csname l@#1\endcsname\l@section
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{%
\oldcontentsline{#1}{\bfseries\MakeTextUppercase{#2}}%
}{%
\oldcontentsline{#1}{#2}%
}%
}
\makeatother
\begin{document}
\tableofcontents
\newpage
\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
\end{document}
So basically I still need the subsections to be in uppercase and the subsubsections should be in italics … Does anyone have an idea how to achieve this? Thank you in advance!
Best Answer
Note that the usage of
tocloft
together with a KOMA-Script class is not recommended.With the next KOMA-Script version 3.20 there is no additional package needed to get the desired result. You can get a pre-release version from the KOMA-Script website: Using most current KOMA-Script with TeX Live, MacTeX or MiKTeX
With KOMA-Script version 3.19a (current on CTAN) or older I would really recommend to use
tocstyle
. Bothtocstyle
and the KOMA-Script classes have the same author. The warning because of the alpha version can be ignored.If you really want to use
tocloft
you can also redefine\addsectiontocentry
etc.