3

I'm using oldstyle numbers in my thesis and noticed that the pagenumbers in the table of contents are not providing a straight left line. The following image shows this behaviour for the numbers from a section with 11 subsections.

In the case of the KOMA-Script classes, the numbers of chapters (or sections in scrartcl) can be modified by adding the Numbers=Monospaced font feature to the sectionentrypagenumber. However, this is not supported (as far as I know) for the lower level sectioning.

How can I get monospaced oldstyle numbers in the TOC?

EDIT: I used @egreg's solution to get the monospaced numbers and added the line

\addtokomafont{disposition}{\rmfamily\addfontfeatures{Numbers=Monospaced}}

to typeset all sectioning in monospaced numbers, too.

Unfortunately, @egreg's solution broke the siunitx package, which started to use normal text font instead of math font. I solved this problem by adding the following line:

\sisetup{math-rm=\symrm}

\documentclass[a5paper,DIV=9]{scrartcl}

\addtokomafont{disposition}{\rmfamily}

\usepackage{fontspec}
\setmainfont{Latin Modern Roman}[Numbers=OldStyle]

\usepackage{lipsum}
\begin{document}
  \tableofcontents

  \section{a}
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \section{a}
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \section{a}
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \section{a}
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum
  \subsection{a}
  \lipsum

\end{document}
2
  • The edit is about a completely different problem
    – egreg
    Aug 8, 2016 at 14:31
  • @egreg Probably. But this problem (I think this is a bug in fontspec/unicode-math) appears with your solution and I wanted to show a possible workaround.
    – Stefan
    Aug 8, 2016 at 16:56

2 Answers 2

3

You can temporarily reset the main font for the table of contents:

\documentclass[a5paper,DIV=9]{scrartcl}

\addtokomafont{disposition}{\rmfamily}

\usepackage{fontspec}
\setmainfont{Latin Modern Roman}[Numbers=OldStyle]

% the following just for testing
\newfontfamily{\msf}{Latin Modern Roman}[Numbers={OldStyle,Monospaced}]

\usepackage{lipsum}
\begin{document}

\begingroup
\setmainfont{Latin Modern Roman}[
  Numbers={OldStyle,Monospaced},
]
\tableofcontents
\endgroup

Numbers should now be not monospaced:

1234567890

{\msf 1234567890}

\section{a}
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\section{a}
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\section{a}
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\section{a}
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\subsection{a}
\lipsum
\subsection{a}
\lipsum

\end{document}

enter image description here

You see from the test that the figures in the top line after the table of contents are not monospaced, while they are in the bottom line.

1
  • I like this solution, because it is very short. To fit the monospaced section numbering, I added \addtokomafont{disposition}{\rmfamily\addfontfeatures{Numbers=Monospaced}}.
    – Stefan
    Jul 28, 2016 at 12:10
2

Another possibility appeared with KOMA-Script v3.20 with the subpackage tocbasic: The font of the toc entries can be modified with the command \DeclareTOCStyleEntry.

For my scrbook, I added the following lines:

% Define new font family with roman font and monospaced, oldstyled numbers
\newfontfamily{\msf}{Latin Modern Roman}[Numbers={OldStyle,Monospaced}]
% switch all headings and pagenumbers in the document
\addtokomafont{disposition}{\msf}
\addtokomafont{pagenumber}{\msf}
% switch entries in toc
\DeclareTOCStyleEntry[entryformat=\msf\bfseries,pagenumberformat=\msf\bfseries]{default}{chapter}
\DeclareTOCStyleEntry[entryformat=\msf,pagenumberformat=\msf]{default}{section}
\DeclareTOCStyleEntry[entryformat=\msf,pagenumberformat=\msf]{default}{subsection}

I decided to switch the entryformat, instead of entrynumberformat, to have a consistent style within the document (cf., \addkomafont{disposition}{...}). Additionally, entrynumberformat inherits from entryformat.

1
  • 1
    You could even make this font-independent by using fontspec’s \addfontfeature command: \DeclareTOCStyleEntry[entryformat={\addfontfeatures{Numbers={Uppercase,Monospaced}}},pagenumberformat={\addfontfeatures{Numbers={Uppercase,Monospaced}}}]{default}{subsection}. In that case, it would always use the default font that you set somewhere else, and therefore when changing the main font, you cannot get a different font in the table of contents by accident. Mar 4, 2017 at 17:52

You must log in to answer this question.

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