How can the font used to set the value and unit with the siunitx package be changed to the main text font used in the document?

Intuitively, the main font should be the standard font setting. However, the math font seems to be used instead, see code below.

% !TeX program = lualatex


\setmainfont{TeX Gyre Heros}

\setmathfont{XITS Math}


The gain $G=\SI{2}{dB}$, which is \SI{1}{dB} higher than before.

enter image description here

2 Answers 2


Excerpting from p. 5 of the user guide of the siunitx package:

By default, all text is typeset in the current upright math font. This can be changed by setting the appropriate options: \sisetup{detect-all} will use the current font for typesetting.

In short, issue the directive \sisetup{detect-all} in the preamble (after loading siunitx, naturally). This will affect not only the output of \SI, but also that of \si, \num, \numlist and all other user macros of the siunitx package.

  • This solves the above problem. In the case the unit is in an equation, for example $G=\SI{1}{dB}$, it seems to me to make sense to typeset the unit ("dB" in this case) in the font of the surrounding text and not the font of the roman math. Is it possible to always use the surrounding text font for the unit?
    – MunHo
    Commented Nov 29, 2017 at 10:28
  • @MunHo - I'm not sure I understand your question. Running \sisetup{detect-all} modifies the font that's used for both the number and the unit in \SI{1}{dB}. Incidentally, do you really use XITS Bold as the default math font?
    – Mico
    Commented Nov 29, 2017 at 10:37
  • I edited the example to reflect this special case. I guess, XITS Bold would be a strange choice of math font in most cases. No, I just wanted to show an example where the contrast was noticeable. The two fonts I use are similar but have slightly different weights.
    – MunHo
    Commented Nov 29, 2017 at 11:01
  • @MunHo - The reason I asked about your math font was, in part, that XITS Bold is a somewhat dubious choice as the argument of \setmathfont. Spefically, do look closely at the shape of the letter G in your updated example and screen shot: It is not XITS Bold, but Computer Modern Math Italic. What's going on? The text font only provides glyphs for text-upright and text-italic cases, but not for math-italic cases. To use XITS for (all) math objects, issue the instruction \setmathfont={XITS Math}. Either that, or also run \setsansfont{TeX Gyre Heros}.
    – Mico
    Commented Nov 29, 2017 at 11:57
  • I had an idea that setting the units in the same font as the units in the text would look more uniform. However, thinking of it, that might not be the case. Anyway, I changed the font above to XITS Math to address your comment.
    – MunHo
    Commented Nov 29, 2017 at 13:15

In recent releases (version 3?) of siunitx, the \sisetup{detect-all} option still works, but is deprecated (see also the package code on GitHub). If you compile with this you will get the following message in the log file:

Package siunitx Info: Option "detect-all" has been deprecated in this release.
(siunitx)             Use "mode = match, propagate-math-font = true,
(siunitx)             reset-math-version = false, reset-text-family = false,
(siunitx)             reset-text-series = false, text-family-to-math = true,
(siunitx)             text-series-to-math = true" as a replacement.

The replacement for it is a series of more granular commands, as shown in the log output above. You can either load the package with


or tweak the settings on-the-fly with


Each of these options are documented in Section 4 of the user manual.

You must log in to answer this question.

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