[Tex/LaTex] sans serif font with siunitx

fontssans-serifsiunitx

My students found this problem, which I could not solve. The percent is always printed in the serif font.

enter image description here

Here is a test code:

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} % T1 Schrift Encoding
\usepackage{lmodern}  % Latin Modern
\usepackage[ngerman]{babel}
\usepackage{float}
\usepackage{siunitx}

\sisetup{%
  mode = math,
  detect-family,
  detect-weight,  
  exponent-product = \cdot,
  number-unit-separator=\text{\,},
  output-decimal-marker={\text{,}},
  math-rm=\mathsf,
  text-rm=\sffamily,
}

\begin{document}
\sffamily\noindent
Text \SI{1.23}{\%} and further text.
\begin{table}[H]
\sffamily
\begin{tabular}{ll}
\SI{1.23}{\%} & 1,23\,\%
\end{tabular}
\end{table}
\end{document}

Best Answer

From page 5 of the siunitx manual:

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

Thus, just replace the options detect-family and detect-weight in the preamble's \sisetup{...} instruction with detect-all, and your students will be all set.

Incidentally, if you run \addto\extrasngerman{\sisetup{locale=DE}} after loading the babel package with the option ngerman, you don't have to specify the options output-decimal-marker={\text{,}} exponent-product = \cdot, and number-unit-separator=\text{\,} explicitly while loading the siunitx package.

enter image description here

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{lmodern} 

\usepackage[ngerman]{babel}
\addto\extrasngerman{\sisetup{locale=DE}}

\usepackage{siunitx}
\sisetup{detect-all} % note: just one option still needs to be specified

\begin{document}
\sffamily
\SI{1.23}{\%}

1,23\,\%
\end{document}
Related Question