4

When looking for some inspiration for how to come up with a template for my thesis, I came across the wonderful classicthesis package. Since I'm working on some very progressive material, however, I was more looking for a modernthesis kind of style and am now composing that for my own taste.

One thing I really like about classicthesis is that the page numbers appear right after section titles in the table of contents. I would also like to have that for my documents, which use KOMA-Script throughout. How can I do that?

3 Answers 3

5

You could use the tocstyle package which is distributed as part of KOMA-Script.

EDIT: The nopagecolumn style uses \normalfont for the page numbers of all sectioning levels; by disabling this for level 1 (section), page numbers will resemble titles (\sffamily\bfseries).

\documentclass{scrartcl}

\usepackage{tocstyle}
\usetocstyle{nopagecolumn}

% Disabling special font commands for sectioning level 1 (section)
\settocstylefeature[1]{pagenumberhook}{}

\begin{document}

\tableofcontents

\section{bla}

\subsection{blubb}

\section{foo}

\subsection{bar}

\end{document}

enter image description here

4
  • This works almost perfectly, thanks! The only issue is that the page number style is strangely altered. Observe for example the 1 behind 1 - bla 1. It is now not bold and sans-serif anymore, but just like all others. Any way to work around this? Or is it maybe even better this way?
    – Ingo
    Commented Jan 5, 2012 at 17:50
  • @tehingo: Sure -- answer updated.
    – lockstep
    Commented Jan 5, 2012 at 18:07
  • Thanks a lot, hope this also inspires other people ;-).
    – Ingo
    Commented Jan 5, 2012 at 18:10
  • @tehingo You're welcome! With regard to your "is it maybe even better" question: I prefer the default behaviour (\normalfont for all page numbers), but there's no "right" or "wrong" here.
    – lockstep
    Commented Jan 5, 2012 at 18:14
4

For those who want to achieve page numbers right after titles using tocloft because this package is already used in their class, this works:

%MWE ONLY
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[lf]{MinionPro} % In this case we have to load the font package!!!
\usepackage{xcolor}
\usepackage{tocloft}

\cftpagenumbersoff{chapter}
\cftsetindents{figure}{0em}{3em}
\cftsetindents{table}{0em}{3em}
\renewcommand{\cftsecleader}{\hspace{.5em}}
\renewcommand{\cftsecafterpnum}{\cftparfillskip}
\renewcommand{\cftsubsecleader}{\hspace{.5em}}
\renewcommand{\cftsubsecafterpnum}{\cftparfillskip}           
%\renewcommand{\cftchapafterpnum}{\vspace{5pt}}
\newcommand{\secfont}{\fontfamily{MinionPro-OsF}\selectfont}
\renewcommand{\cftsecpagefont}{\secfont\color{blue}}
\renewcommand{\cftsubsecpagefont}{\secfont\color{blue}}

\begin{document}

\tableofcontents

\section{bla}

\subsection{blubb}

\section{foo}

\subsection{bar}

\end{document}

If you now include this piece of code in your thesis and use a better color you will get a result like the following:

toc layout using tocloft and above code

3
  • I copied this code but it didn't work as your image is showing. In particular it worked fine just for the sections, but not for subsec. & subsubsec. Can u tell me why?
    – Francesco
    Commented Mar 19, 2016 at 14:35
  • @Francesco I think that the class I used redefined some commands I missed. Thanks for the hint! I'll fix this asap.
    – user49121
    Commented Mar 24, 2016 at 21:08
  • @Francesco The solution is to also insert for example \renewcommand{\cftsecfont}{\sffamily\bfseries} or \renewcommand{\cftsubsecfont}{...}. You can find all these commands in texdoc tocloft. I hope that helps.
    – user49121
    Commented Mar 24, 2016 at 21:20
2

With an uptodate KOMA-Script Version (3.20 or newer) there is no additional package needed:

\documentclass{scrartcl}[2016/05/19]% needs version 3.20 or newer

\RedeclareSectionCommands[
  tocraggedpagenumber,
  toclinefill=\hspace{1em}
]{section,subsection,subsubsection,paragraph,subparagraph}

\begin{document}
\tableofcontents
\section{bla}
\subsection{blubb}
\section{foo}
\subsection{bar}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .