2

I use the following code to change the font to sans serif. I would like to use TeX Gyre Heroes and copied the code snipped from tug.dk.

\documentclass{article}

\usepackage{tgheros}
\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}

\usepackage{siunitx}

\begin{document}

2 K, 2 Kelvin, \SI{2}{K}, \SI{2}{Kelvin}

\end{document}

However, the result is not as expected:

all in effect

The fonts are slightly different. Leaving the \usepackage{tgheroes} out leads to

no_tgheroes

which seems okay. Leaving the \renewcommand... out also seems to work, now with a serif font.

no_renew

Is this a side effect of a combination of all 3 (siunitx, tgheroes, renew...)?

2

Declaring \renewcommand{\familydefault}{\sfdefault} doesn't change the \mathsf font; siunitx realizes that it's in a sans serif context and so uses \mathsf.

Add

\DeclareMathAlphabet{\mathsf}{OT1}{\sfdefault}{m}{n}
\SetMathAlphabet{\mathsf}{bold}{OT1}{\sfdefault}{b}{n}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgheros}
\usepackage{siunitx}

\DeclareMathAlphabet{\mathsf}{OT1}{\sfdefault}{m}{n}
\SetMathAlphabet{\mathsf}{bold}{OT1}{\sfdefault}{b}{n}

\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

\begin{document}

2 K, 2 Kelvin, \SI{2}{K}, \SI{2}{Kelvin}

\bfseries
2 K, 2 Kelvin, \SI[detect-weight]{2}{K}, \SI[detect-weight]{2}{Kelvin}

\end{document}

The second line is just to see that the right font is chosen in the (unlikely) case you need detect-weight.

enter image description here

Alternatively, add the option mode=text (I wouldn't recommend it, though):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgheros}
\usepackage{siunitx}

\sisetup{mode=text}

\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

\begin{document}

2 K, 2 Kelvin, \SI{2}{K}, \SI{2}{Kelvin}

\bfseries
2 K, 2 Kelvin, \SI[detect-weight]{2}{K}, \SI[detect-weight]{2}{Kelvin}

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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