In a sans serif document (with \renewcommand{\familydefault}{\sfdefault}
) I'd like to have units and numbers in text mode set in sans serif, and numbers and units in math mode (inline or display) in roman as all other math is also in roman.
I've created a test document to try different options, but I've not found options in siunitx (version 3) that leads to the desired behavior† (see code at the end). In the images I've marked the cases where the font family is not what I would expect.
Without any \sisetup
(same as \sisetup{reset-text-family = false, reset-text-series = false, reset-text-shape = false}
):
With \AtBeginDocument{\sisetup{unit-font-command = \mathrm}}
:
With \sisetup{detect-all = true}
, regardless of unit-font-command
:
With \sisetup{mode = match}
, regardless of unit-font-command
:
\documentclass{article}
\usepackage[margin=3cm]{geometry} % just to fit 3 tables in one line
\usepackage{siunitx}
%\AtBeginDocument{\sisetup{unit-font-command = \mathrm}}
%\sisetup{detect-all = true}
%\sisetup{mode = match}
%\sisetup{reset-text-family = false, reset-text-series = false, reset-text-shape = false}
\renewcommand{\familydefault}{\sfdefault} % My document should be in sans serif
\begin{document}%
Some text where the voltage $u$ is \qty{5}{\kilo\volt},
also containing the equation \(u = \qty{5}{\kilo\volt}\).
And display math:
\[
u = \qty{5}{\kilo\volt}
\]
\end{document}
Seemingly related questions that don't help:
- siunitx with sans serif font in text but serif font in math (I don't use XeLaTeX and the problem occurs without fontspec)
- Can I make siunitx commands use serif fonts like the rest of the math in beamer? (solution does not do what I want, as shown above)
- sans serif font with siunitx (different problem)
†I have to admit that I find the font configuration in siunitx v3 pretty complex and confusing, and I've not gone beyond trial and error. Although it is probably quite powerful once understood. It does not help though, that most search results now yield obsolete solutions for version 2, which don't apply to the new version 3. In my personal humble opinion it would have been better to use a new name for the rewritten package to avoid this confusion and breakage (of course at the cost of other drawbacks).