3

I try to modify my table of contents. In the picture below you see how my table of contents should look like.

I already removed the heading, modified the intends. I tried to remove the dots, change the vspacing, bold letters but it doesnt work... I already read the tocloft docu, but my code didnt work. Here is my code. Hope you can help me. THX

%Dokumentklasse
\documentclass[a4paper,11pt, pointlessnumbers,  twoside]{scrreprt}    
\usepackage{tocloft} 
\makeatletter 
\renewcommand*\l@section{\bprot@dottedtocline{1}{0em}{2.3em}}
\renewcommand*\l@subsection{\bprot@dottedtocline{2}{1.5em}{2.5em}}
\makeatother 
\begin{document}
%===Inhaltsverzeichnis===%
\renewcommand\cftsecdotsep{2000}
\renewcommand\cftsubsecdotsep{2000}
%\renewcommand{\cftsectiondotsep}{\cftnodots}
\renewcommand{\contentsname}{}
\tableofcontents

\chapter{Just}

\chapter{Checking}

\section{To see}

\section{If I}

\subsection{Can Duplicate}

\subsection{The problem}

\section{Here}

\chapter{In the TOC}

\end{document}

It should look that way:

enter image description here

  • 1
    Please do never ever post screenshots of code again. – MaestroGlanz Oct 20 '16 at 16:32
  • Oh okay, sorry. – muella91 Oct 20 '16 at 16:33
  • 2
    KOMA-script can do (all of?) the stuff by its own. No need for tocloft. In fact, `tocloft and KOMA are incompatible with some features. – Johannes_B Oct 20 '16 at 16:37
  • This is no MWE. Please provide MWEs, if you post a question. – MaestroGlanz Oct 20 '16 at 16:46
  • @Johannes_B Behalf of the poster: Do you have any recommendations to look this up? – MaestroGlanz Oct 20 '16 at 16:47
3

Here is a suggestion using the possibilities of KOMA-Script. It needs at least KOMA version 3.20 (current is 3.21).

\documentclass[
  numbers=noenddot,
  twoside,
  ngerman
]{scrreprt}[2016/05/10]
\usepackage{babel}

\usepackage[headsepline,plainheadsepline,automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead*{\pagemark}
\ihead{\headmark}
\addtokomafont{pagehead}{\normalfont}

\deftocheading{toc}{}
\BeforeTOCHead[toc]{\markboth{\contentsname}{\contentsname}}
\AfterTOCHead[toc]{\thispagestyle{scrheadings}}

\usepackage{xpatch}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\addtocentrydefault{chapter}{#1}{\MakeUppercase{#2}}}
  {}{\PatchFailed}

\RedeclareSectionCommand[
  tocindent=0pt,
  tocnumwidth=2.3em,
  tocbeforeskip=1em plus 1pt,
  tocentryformat=\textbf,
  tocpagenumberformat=\textbf
]{section}
\RedeclareSectionCommand[
  tocindent=1.5em,
  tocnumwidth=2.5em
]{subsection}

\RedeclareSectionCommands[
  toclinefill=\hfill
]{section,subsection,subsubsection,paragraph,subparagraph}

\renewcommand\pagemark{{\usekomafont{pagenumber}\pagename \enskip\thepage}}
\providecaptionname{ngerman}{\pagename}{Seite}

\renewcaptionname{ngerman}{\figurename}{Abb.}
\renewcaptionname{ngerman}{\tablename}{Tab.}
\addtokomafont{captionlabel}{\bfseries}

\renewcommand\familydefault{\sfdefault}

\begin{document}
\pagenumbering{Roman}
\tableofcontents

\cleardoubleoddpage
\pagenumbering{arabic}
\chapter{Just}
\chapter{Checking}
\section{To see}
\section{If I}
\subsection{Can Duplicate}
\subsection{The problem}

\section{Here}

\chapter{In the TOC}

\end{document}

Result:

enter image description here

0

Okay, so it seems as though what you want are the following:

  • Chapter and section titles in bold; subsection titles in normal weight.
  • Chapter headings in all caps
  • No leaders connecting the titles to the page numbers.
  • Both chapter and section entries flush to the left margin, with subsection entries indented.

Let's address these in turn. To get chapter and section titles in bold, look at page 9 of the tocloft manual. Specifically, look at \cftXfont. If you set this to \bfseries (with something like \renewcommand{\cftchapfont}{\bfseries} and \renewcommand{\cftsecfont}{\bfseries}, you'll get your entries in bold.

Chapter headings in all caps: this one's tougher, due to the nature of LaTeX's \uppercase command. Still, it's basically a short incantation to patch an internal LaTeX command:

\makeatletter
\patchcmd{\l@chapter}{#1}{\uppercase{#1}}{}{}%
\makeatother

Don't forget to add \usepackage{etoolbox} to your preamble for this. This should solve that problem.

For getting rid of the leaders, look at page 8 of the tocloft manual; specifically, \cftdot. Just set it to nothing; e.g., \renewcommand{\cftdot}{}. You will no longer have leaders in your TOC.

Finally, for the indentation, see page 10 of the tocloft manual; specifically, \cftsetindents. Set your chapter and section indents to zero, and your subsection indents to whatever you'd like them to be; e.g.:

\cftsetindents{chapter}{0em}{2em}
\cftsetindents{section}{0em}{2em}
\cftsetindents{subsection}{1.5em}{2.5em}

(The last argument takes care of the width of the numbers for that level of the TOC.) And that takes care of that.

Do all of this, trimming your example down to the necessary parts, and you end up with something like the following:

\documentclass[a4paper,11pt, pointlessnumbers,  twoside]{scrreprt}
\usepackage{tocloft} 
\usepackage{etoolbox} 
\begin{document}
\renewcommand{\cftdot}{}
\renewcommand{\cftchapfont}{\bfseries}
\makeatletter
\patchcmd{\l@chapter}{#1}{\uppercase{#1}}{}{}%
\makeatother
\renewcommand{\cftsecfont}{\bfseries}
\cftsetindents{chapter}{0em}{2em}
\cftsetindents{section}{0em}{2em}
\cftsetindents{subsection}{1.5em}{2.5em}
\renewcommand{\contentsname}{}
\tableofcontents

\chapter{Just}

\chapter{Checking}

\section{To see}

\section{If I}

\subsection{Can Duplicate}

\subsection{The problem}

\section{Here}

\chapter{In the TOC}

\end{document}

Which gives you a TOC that looks like this:

TOC with the requested properties

Now, it looks like there are a few other things you might want to change (e.g., spacing between chapters and sections), but the tocloft documentation is quite complete and should give you the information you need.

Hope this helps.

  • Did you run the MWE I posted? It works here. – dgoodmaniii Oct 21 '16 at 1:36

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.