Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
Why didn't you introduce the student who found the problem to tex.sx and let them ask this question themselves? ;) –  doncherry Nov 18 '11 at 13:37
2  
I did that, but I also want to get my lecture finished, so that I can publish the slides. And the discussion on how to get help is a topic for the next and last lecture next week... –  Matthias Pospiech Nov 18 '11 at 13:47
    
why the \, before the \%? That should not be nessary –  daleif Nov 18 '11 at 13:50
1  
That was a copy-paste error. I know that it should not be there. I have removed it from the code –  Matthias Pospiech Nov 18 '11 at 14:41

3 Answers 3

up vote 9 down vote accepted

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.

share|improve this answer
    
But \SI{1.23}{\text{\%}} is very counter-intuitive. So I am still looking for a better solution. –  Matthias Pospiech Nov 18 '11 at 13:48
    
Ok, detect-all solves the problem. But i wonder why this is not default? –  Matthias Pospiech Nov 18 '11 at 13:50
    
Might be because some of these extra features slows down the parsing. So only enabling them when needed may be quite useful. For example typesetting large tables with siunitx soon become very slow, I have some tables that can take 10 sec to compile (each), rather anoying. –  daleif Nov 18 '11 at 13:54
2  
The detect-all switch actually turns on four separate detect-... conditions. The one that your students were missing was detect-mode. The two other switches that were already set by them (detect-family, detect-weight) remain turned on, of course, when they're superseded by detect-all. See pp. 17-19 of the manual for more details. –  Mico Nov 18 '11 at 13:59
2  
Remember the standard settings in siunitx are supposed to follow the 'rules': units should be given in an upright roman font irrespective of the surrounding text. (Mathematically, \mathrm{m} and \mathsf{m} are not the same thing, hence the presumption that even the most basic font changes should be ignored.) –  Joseph Wright Nov 18 '11 at 13:59

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.

share|improve this answer

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.