3

I need to set a custom font (installed in my OS) for my documents, according to my company's style guidelines.

I was able to successfully set "Gotham Book" as main font, but for some reason, my TOC results in chapter lines still using the default font (section font is correct instead).

I've searched a lot but probably I'm missing the underlying problem, as I'm still new to Tex.


Here's my code:

\documentclass[a4paper,12pt]{scrreprt}
\usepackage{fontspec}
\setmainfont{Gotham Book}
\newfontfamily{\chapterfont}{Gotham Book}
\newfontfamily{\sectionfont}{Gotham Book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lipsum}

\begin{document}

\tableofcontents

\chapter{first chapter}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{second chapter}
\lipsum{1}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{third chapter}
\lipsum{1}

\end{document}

And here's the resulting TOC:

TOC

  • 2
    \documentclass[a4paper,12pt,egregdoesnotlikesansseriftitles]{scrbook} – egreg Feb 13 '17 at 9:54
  • Note that in the scrreprt class, the font for the section entries in the ToC is the main font. You can set the font for all titles with \setkomafont{disposition}{\normalcolor <<Your font>>}. – TonioElGringo Feb 13 '17 at 10:22
2

The komascript classes use, by default, the sans serif font family for titles.

Since you're using a sans serif font for the whole document you have a few possibilities. I used DejaVu Sans, not having Gotham Book on my machine.

First possibility

Define the sans serif font family

\documentclass[
  a4paper,
  12pt,
]{scrreprt}
\usepackage{fontspec}
\usepackage[english]{babel}
\usepackage{lipsum}

\setmainfont{DejaVu Sans}
\setsansfont{DejaVu Sans}

\begin{document}

\tableofcontents

\chapter{first chapter}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{second chapter}
\lipsum{1}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{third chapter}
\lipsum{1}

\end{document}

Second possibility

Change the standard font for titles (the name is disposition, probably a bad translation).

\documentclass[
  a4paper,
  12pt,
]{scrreprt}
\usepackage{fontspec}
\usepackage[english]{babel}
\usepackage{lipsum}

\setmainfont{DejaVu Sans}

\setkomafont{disposition}{\normalfont\bfseries}

\begin{document}

\tableofcontents

\chapter{first chapter}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{second chapter}
\lipsum{1}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{third chapter}
\lipsum{1}

\end{document}

Third possibility

Use the class option for the purpose, which has a rather funny name:

\documentclass[
  a4paper,
  12pt,
  egregdoesnotlikesansseriftitles,
]{scrreprt}
\usepackage{fontspec}
\usepackage[english]{babel}
\usepackage{lipsum}

\setmainfont{DejaVu Sans}

\begin{document}

\tableofcontents

\chapter{first chapter}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{second chapter}
\lipsum{1}
\section{first section}
\lipsum{1}
\section{second section}
\lipsum{1}
\chapter{third chapter}
\lipsum{1}

\end{document}

Output

Table of contents

enter image description here

Chapter page

enter image description here

Somehow Markus Kohm realized I suggested a document class option for making titles in serif type (better, in the default font family associated to \familydefault instead of sans serif). I had pointed out that using \setkomafont for this is awkward: see the “second possibility” in order to understand my point. The answer was the addition of a silly-named option.

  • Perhaps cheating is the simplest way? If the entire document does not use a genuine sans-serif font anywhere, why not \setsansfont{Gotham Book} so that Gotham Book (a serif font) is used in place of sans? – user103221 Feb 13 '17 at 16:48
  • @RobtA Isn't this cover in the first possibility? – egreg Feb 13 '17 at 16:49
  • I interpreted the first possibility as being the other way around (using sans everywhere). I must have misunderstood it. – user103221 Feb 13 '17 at 16:51
1

With the scrreprt class, the font used for section entries in the table of contents is the main document font. In your example, the \newfontfamily calls do nothing at all.

You probably want to change all section titles fonts, since by default they use \normalcolor\sffamily\bfseries and your font is sans-serif. You can use the \setkomafont for this:

\setmainfont{Gotham Book}
\setkomafont{disposition}{\normalcolor\bfseries}% Removed \sffamily

If you only want to change the ToC entries font, use \setkomafont{chapterentry}{...} instead.

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.