3

What I want: S column type in tables to use tabular/lining figures. \SI, \num, \SIrange, etc all to use old-style/proportional numbers.

I recently asked a question about getting siunitx to work with old-style numerals. At the time I had the issue that all siunitx numbers were lining figures.

I've now moved to using fontspec/lualatex/newcomputermodern and have the reverse issue: Everything is proportional old-style figures, even inside tables, which I want to be tabular/lining.

siunitx's detect-all setting is no longer doing anything, which means I can't use the previous answer.

MNWE:

\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures+{Numbers=OldStyle}
\usepackage{newcomputermodern}
\usepackage{siunitx}

\begin{document}

\sisetup{detect-all=false}
\string\sisetup{detect-all=false}

\noindent 1234567890 Text \\
\(1234567890\) Math \\
\SI{1234567890}{\angstrom} siunitx

\begin{tabular}{Sl}
    1.234(5678) &   12345678901234567890\\
    1.111(1111) &   11111111111111111111  \\
\end{tabular}

\vspace{1 cm}
\sisetup{detect-all=true}
\string\sisetup{detect-all=true}

\noindent 1234567890 Text \\
\(1234567890\) Math \\
\SI{1234567890}{\angstrom} siunitx

\begin{tabular}{Sl}
    1.234(5678) &   12345678901234567890\\
    1.111(1111) &   11111111111111111111  \\
\end{tabular}

\end{document}

This shows that math environments are lining figures, text are old style, and \si and S columns ignore both settings and are old style

2
  • You appear to not have carried over \DeclareSymbolFontAlphabet{\mathrm}{operators} from my previous answer to your new setup. Was this deliberate?
    – Mico
    Commented Dec 30, 2020 at 4:27
  • 1
    @Mico It was not, I likely missed that when testing and thus gave up and asked the question. Sorry.
    – Canageek
    Commented Dec 30, 2020 at 20:00

2 Answers 2

2

I think the key to getting siunitx's macros \SI and \num and the S column type to work you want them to is to execute \DeclareSymbolFontAlphabet{\mathrm}{operators}, an instruction which you provided in your query a few weeks ago but left off from the code in your new query.

The following code produces the exact same desired output -- oldstyle numerals produced by \num and \SI but not by the S column type -- under pdfLaTeX, LuaLaTeX, and XeLaTEX. (Lining numerals are hightlighted in yellow. I use Latin Modern rather than the newcomputermodern package since I'm not familiar with the latter.)

enter image description here

\documentclass{article}

\usepackage{iftex} % for \ifpdftex macro
\ifpdftex
  \usepackage[T1]{fontenc}
  \usepackage{cfr-lm} % text fonts
  % (use default math font, i.e., CM Math)
\else
  \usepackage{unicode-math} % loads 'fontspec' automatically
  \setmainfont{Latin Modern Roman}[Numbers=OldStyle]
  \setmathfont{Latin Modern Math} % optional
\fi

\usepackage{siunitx}
\DeclareSymbolFontAlphabet{\mathrm}{operators} % <-- very important

\usepackage{letltxmacro}
%% redefine \SI and \num -- carefully
\LetLtxMacro\origSI\SI
\LetLtxMacro\orignum\num
\renewcommand\SI[3][mode=text]{\origSI[#1]{#2}{#3}}
\renewcommand\num[2][mode=text]{\orignum[#1]{#2}}

\begin{document}

\begin{tabular}{@{} l l @{}}
1234567890     & Text   \\
$1234567890$   & Math   \\[1ex]
\SI{1234567890}{\meter}     & \string\SI     \\
\origSI{1234567890}{\meter} & \string\origSI \\[1ex]
\num{1234567}               & \string\num    \\
\orignum{1234567}           & \string\orignum\\[1ex]
\end{tabular}

\begin{tabular}{@{} l S[table-format=1.3] @{}}
    l & {S} \\
    \hline
    1.2345 &   1.2345  \\
    1.1111 &   1.1111  \\
\end{tabular}

\end{document}
2

New Answer

You can set \SI and \begin{tabular}{S} to use a different font with the option text-rm=. Here is a MWE that sets both up to use fixed-width, old-style numbers:

\documentclass{article}
\usepackage{unicode-math}

\setmainfont{NewComputerModernBook}[Numbers=OldStyle]
\setsansfont{NewComputerModernSansBook}[Numbers=OldStyle]
\setmonofont{NewComputerModernMonoBook}[Numbers=OldStyle]
\setmathfont{NewCMMath-Book}
%\setmathrm{NewComputerModernBook}[Numbers={Lining,Tabular}]
\newfontface\tablefont{NewComputerModernBook}[Numbers={OldStyle,Tabular}]

\usepackage[text-rm=\tablefont, detect-all=true]{siunitx}

\begin{document}

\noindent 1234567890 Text \\
\(1234567890\) Math \\
\SI{1234567890}{\angstrom} siunitx

\begin{tabular}{Sl}
    1.234(5678) &   12345678901234567890\\
    1.111(1111) &   11111111111111111111  \\
\end{tabular}

\end{document}

New Computer Modern tabular old-style

And here is a new tabular environment that redefines the font siunitx uses, locally:

\documentclass{article}
\usepackage{unicode-math}

\setmainfont{NewComputerModernBook}[Numbers=OldStyle]
\setsansfont{NewComputerModernSansBook}[Numbers=OldStyle]
\setmonofont{NewComputerModernMonoBook}[Numbers=OldStyle]
\setmathfont{NewCMMath-Book}
%\setmathrm{NewComputerModernBook}[Numbers={Lining,Tabular}]
\newfontface\tablefont{NewComputerModernBook}[Numbers={Lining,Tabular}]

\usepackage[detect-all=true]{siunitx}
\usepackage{xparse} % Included by default in recent versions of LaTeX.

\NewDocumentEnvironment{SItabular}{o m}%
  {\sisetup{detect-all=true, text-rm=\tablefont}\begin{tabular}[#1]{#2}}
  {\end{tabular}}

\begin{document}

\noindent 1234567890 Text \\
\(1234567890\) Math \\
\SI{1234567890}{\angstrom} siunitx
\bigskip

\begin{SItabular}{Sl}
    1.234(5678) &   12345678901234567890\\
    1.111(1111) &   11111111111111111111  \\
\end{SItabular}

\bigskip
\SI{1234567890}{\angstrom} siunitx

\end{document}

New Computer Modern sample

This avoids redefining existing commands.

Original Answer

One solution is to set your \mathrm font to a version of the text font with Numbers={Lining,Tabular}, and tell siunitx to use the font [math-rm].

\documentclass{article}
\usepackage{unicode-math}
\usepackage[math-rm]{siunitx}

\setmainfont{NewComputerModernBook}[Numbers=OldStyle]
\setsansfont{NewComputerModernSansBook}[Numbers=OldStyle]
\setmonofont{NewComputerModernMonoBook}[Numbers=OldStyle]
\setmathfont{NewCMMath-Book}
\setmathrm{NewComputerModernBook}[Numbers={Lining,Tabular}]

\begin{document}

\sisetup{detect-all=false}
\string\sisetup{detect-all=false}

\noindent 1234567890 Text \\
\(1234567890\) Math \\
\SI{1234567890}{\angstrom} siunitx

\begin{tabular}{Sl}
    1.234(5678) &   12345678901234567890\\
    1.111(1111) &   11111111111111111111  \\
\end{tabular}

\vspace{1 cm}
\sisetup{detect-all=true}
\string\sisetup{detect-all=true}

\noindent 1234567890 Text \\
\(1234567890\) Math \\
\SI{1234567890}{\angstrom} siunitx

\begin{tabular}{Sl}
    1.234(5678) &   12345678901234567890\\
    1.111(1111) &   11111111111111111111  \\
\end{tabular}

\end{document}

In this example, the \SI command and the S column of the first table, with detect-all=false, display lining tabular numbers.

Another is to use the \tablenums command from siunitx. Another is to use the font [text-tt].

3
  • I hate to say it, but this answer doesn't actually accomplish what I asked. This has the S column type and \SI using the same type of numbers (lining or old style) and what I asked was for \SI to use old style while S uses lining.
    – Canageek
    Commented Dec 30, 2020 at 20:33
  • @Canageek Okay. I wrote two new answers that should be closer to what you wanted.
    – Davislor
    Commented Dec 31, 2020 at 4:33
  • @Canageek Sorry for the mistake!
    – Davislor
    Commented Dec 31, 2020 at 9:02

You must log in to answer this question.

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