# TOC with monospaced oldstyle numbers

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

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}

\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}
• The edit is about a completely different problem – egreg Aug 8 '16 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 '16 at 16:56

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

\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}

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.

• 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 '16 at 12:10

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