sans serif font with siunitx

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}

The problem is that you are assuming that % in \mathsf 'looks' sanserif, but it does not

\documentclass{article}
\begin{document}
$\mathsf{\%}$
\end{document}

Either stick to text mode for units

\documentclass{article}
\usepackage{siunitx}
\sisetup
  {
    math-rm=\mathsf,
    text-rm=\sffamily
  }
\begin{document}
\SI{1.23}{\%}
\end{document}

force text mode for this particular case

\documentclass{article}
\usepackage{siunitx}
\sisetup
  {
    mode = math,
    math-rm=\mathsf
  }
\begin{document}
\SI{1.23}{\text{\%}}
\end{document}

or use the symbolic mode and an appropriate definition

\documentclass{article}
\usepackage{siunitx}
\sisetup
  {
    mode = math,
    math-rm=\mathsf
  }
\DeclareSIUnit{\percent}{\text{\%}}
\begin{document}
\SI{1.23}{\percent}
\end{document}

In all cases, note that extra spacing should not be added to the unit part: there is an automatic space between the number and the unit.


As already have been mentioned the source of the problem is that you typeset the percent in mathmode and assumed that \mathsf{\%} gives a sans serif percent. But the percentchar has mathcode hex 25, the \math... commands affect only chars with math code > hex 7000. You would get the expected result if you would change the mathcode:

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

\begin{document}
$\mathbf{\% a}\mathsf{\% a} \% a$

\mathcode`\%="7025
$\mathbf{\% a}\mathsf{\% a} \% a$

\end{document}