4

I would like to customize the listing of the chapters given in the table of contents in a scrbook document. Given the following example:

\documentclass{scrbook}
\begin{document}
\tableofcontents
\chapter{Alpha}
\chapter{Beta}
\chapter{Gamma}
\end{document}

My TOC currently looks like this:

TOC

How can I customize the text printed in the TOC in the following two regards:

  • add a prefix/suffix to the number, e.g. write "Chapter 1" instead of "1"
  • increase letter spacing of the chapter title using microtype's textls
qqilihq
  • 927

2 Answers2

5

The command \textls works like \textbf. So you need the single command \lsstyle which is similar to \bfseries.

The prefix can be added by the font element chapterentry:

\documentclass{scrbook}
\usepackage{microtype}
\addtokomafont{chapterentry}{\lsstyle  Chapter~}
\begin{document}
\tableofcontents
\chapter{Alpha}
\chapter{Beta}
\chapter{Gamma}
\end{document}

enter image description here

Marco Daniel
  • 95,681
  • This works, but \addtokomafont was not intended for this. – Manuel Jun 01 '14 at 14:29
  • @Manuel: I know. But sometimes you have to expand the meaning ;-) – Marco Daniel Jun 01 '14 at 14:34
  • I had the same feeling as @Manuel. How can this be set properly? Should the OP go for titletoc package? – Mario S. E. Jun 01 '14 at 14:52
  • @Manuel: Are you saying this because the macro involved has the word "font" in it? The alternative is to redefine \l@chapter directly, which requires far more obscurity than a user-interface like \addtokomafont or \setkomafont. I think this is perfectly fine. – Werner Jun 01 '14 at 15:13
  • @MarcoDaniel Thank you for the hint with lsstyle, however, can I also adjust the spacing numerically using lsstyle, similary to textls? (I only need to add a subtle more spacing there, the lsstyle default is too much). – qqilihq Jun 01 '14 at 16:11
  • @Werner I was just pointing it out. There's even a limitation (in some cases*) in what can go inside it (e.g., \centering), so obviously adding Chapter~ is not recommended. – Manuel Jun 01 '14 at 16:24
2

Here is another suggestion based on the example in this article by Markus Kohm at www.komascript.de

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{microtype}

\newcommand*{\SavedOriginaladdchaptertocentry}{}
\let\SavedOriginaladdchaptertocentry\addchaptertocentry
\renewcommand*{\addchaptertocentry}[2]{%
  \ifstr{#1}{}{% entry without number
    \SavedOriginaladdchaptertocentry{#1}{#2}%
  }{% entry with number
    \SavedOriginaladdchaptertocentry{}{%
      \string\expandafter\string\MakeUppercase\string\chaptername
      ~#1\string\quad\textls[500]{#2}}%
  }%
}%

\begin{document}
\tableofcontents
\addchap{Preface}
\chapter{Alpha}
\chapter{Beta}
\chapter{Gamma}
\addchap{Appendix}
\end{document}

enter image description here

I have increased the letter spacing to show the effect.

If the letter spacing should be increased for the whole chapterentry you can use

\newcommand*{\SavedOriginaladdchaptertocentry}{}
\let\SavedOriginaladdchaptertocentry\addchaptertocentry
\renewcommand*{\addchaptertocentry}[2]{%
  \ifstr{#1}{}{% entry without number
    \SavedOriginaladdchaptertocentry{#1}{#2}%
  }{% entry with number
    \SavedOriginaladdchaptertocentry{}{%
      \string\expandafter\string\MakeUppercase\string\chaptername
      ~#1\string\quad{}#2}%
  }%
}%
 \addtokomafont{chapterentry}{\textls[200]}

Note that \textls[200] have to be the last command for the chapterentry font element because it needs an argument

enter image description here

esdd
  • 85,675