1

The table of contents in my document looks like this at the moment: enter image description here

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!

kanra
  • 196
  • 1
  • 12
  • A "quick and dirty" solution would be to 'hack' short titles and define layout just for ToC entries (cf. e.g. this answer) – ebosi Mar 17 '16 at 11:53
  • you can use \setkomafont. see here for help: http://tex.stackexchange.com/questions/241210/fonts-used-in-scrrprt-toc – naphaneal Mar 17 '16 at 12:13
  • If possible I'd prefer a not-so-dirty solution ... Though, thanks for your answer! As for the second suggestion: I tried to give setkomafont the arguments \MakeUppercase, \MakeTextUppercase and \MakeHyperLinkStartUppercase but none of these worked ... (also, I'd like to avoid the tocstyle package) – kanra Mar 17 '16 at 13:26

1 Answers1

1

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

\documentclass[headings=normal, hidelinks]{scrartcl}[2016/03/16]
\usepackage{blindtext}% dummy text
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4} 

\RedeclareSectionCommand[
  tocnumsep=15pt,
  toclinefill=\TOCLineLeaderFill,
  tocpagenumberformat=\normalfont
]{section}
\RedeclareSectionCommand[tocnumsep=15pt]{subsection}
\RedeclareSectionCommand[tocentryformat=\itshape,tocnumsep=12pt]{subsubsection}
\RedeclareSectionCommand[tocnumsep=12pt]{paragraph}

\renewcommand\addsectiontocentry[2]{%
  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}

\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}
\blinddocument
\blinddocument
\end{document}

enter image description here


With KOMA-Script version 3.19a (current on CTAN) or older I would really recommend to use tocstyle. Both tocstyle and the KOMA-Script classes have the same author. The warning because of the alpha version can be ignored.

\documentclass[headings=normal, oneside, hidelinks]{scrartcl}
\usepackage{blindtext}% dummy text

\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}{\bfseries} 
\settocfeature[toc][3]{entryhook}{\itshape} 
\settocfeature[toc][4]{entryhook}{}

\renewcommand\addsectiontocentry[2]{%
  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}

\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}
\blinddocument
\blinddocument
\end{document}

If you really want to use tocloft you can also redefine \addsectiontocentry etc.

\documentclass[headings=normal, oneside, hidelinks]{scrartcl}
\usepackage{blindtext}% dummy text

\usepackage{tocloft}
\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} 

\renewcommand\addsectiontocentry[2]{%
  \addtocentrydefault{section}{#1}{\texorpdfstring{\bfseries\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsubsectiontocentry[2]{%
  \addtocentrydefault{subsubsection}{#1}{\texorpdfstring{\itshape#2}{#2}}%
}

\begin{document} 
\tableofcontents
\newpage

\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
\blinddocument
\blinddocument
\end{document}

enter image description here

esdd
  • 85,675
  • I will probably use the KOMA script Version as soon as the error message doesn't show up anymore. But for now, this alternative solution works great - thank you for the detailed answer! – kanra Mar 22 '16 at 12:57