1

I am looking for a way to change the style of chapters in the TOC that belong to the front matter. Below I posted a minimal example code to illustrate my goal:

\documentclass{scrbook}
\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}

Here, I would like to have the two frontmatter chapters Preface and Acknowlegements to be written in non-bold italics in the TOC, including their page numbers. I manage to write their names in the required style by simply using e.g.

\chapter[\itshape\textmd{Preface}]{Preface}

but this does not change the formatting of the page number.

2

I define a new cs \matter@switch and appended it to the chapterentry KOMA font. Then I added macros to \frontmatter and \mainmatter which write a redefinition of \matter@switch to the toc file. (I'm sure the code below can be optimized)

\documentclass{scrbook}
\makeatletter
\newcommand\matter@switch{}
\addtokomafont{chapterentry}{\matter@switch}
\g@addto@macro\frontmatter{%
  \addtocontents{toc}{%
    \protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
  }%
}
\g@addto@macro\mainmatter{%
  \addtocontents{toc}{%
    \protect\renewcommand\protect\matter@switch{}%
  }%
}
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{Acknowledgements}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}

enter image description here

2

This can be achieved by changing the chapter title font/page fonts using the tocloft package and its various commands, \cftchapterfont and \cftchapterpagefont. However, this commands persist until explicitly changed while the ToC is processed. Therefore it's necessary to write the switch back commands directly to the ToC using \addtocontents.

\documentclass{book}
\usepackage{tocloft}%
\begin{document}
\let\cftchapfontorig\cftchapfont
\let\cftchappagefontorig\cftchappagefont
\renewcommand{\cftchapfont}{\itshape}
\renewcommand{\cftchappagefont}{\itshape}%
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\addtocontents{toc}{\protect\renewcommand{\cftchapfont}{\cftchapfontorig}}
\addtocontents{toc}{\protect\renewcommand{\cftchappagefont}{\cftchappagefontorig}}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}

enter image description here

  • Have you heard of \setkomafont and \usekomafont? This seems to be more appropriate than using a package. – Henri Menke Sep 16 '14 at 10:32
  • What would be the names of the elements I have to change when using '\setkomafont'? I didn't find a comprehensive list in the koma documentation to figure out the name of the respective toc elements. – shiin Sep 16 '14 at 11:09
  • @shiin: This should be answered by Henri Menke -- I provided a solution without \setkomafont -- it should work for other documentsclasses as well – user31729 Sep 16 '14 at 11:10
  • @HenriMenke I tried using \setkomafont{chapterentry}{\sffamily\itshape} and \setkomafont{chapterentrypagenumber}{\sffamily\itshape}. While this changes the style, it's a global change and cannot simply be changed back for the chapters in the main matter. – shiin Sep 16 '14 at 11:36
  • @ChristianHupfer I just tested the tocloft package. It doesn't seem to be a good solution for various reasons: a) It does not respect the default settings of scrbook (e.g. non-serif page numbers for chapters), and more imporantly b) the toc is no longer considered as a separate chapter (starting on a right page with a chapter header, a pdf bookmark, ...). – shiin Sep 16 '14 at 12:19

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.