[Tex/LaTex] scale default sans font

fontsfontsize

Consider the following minimal document:

\documentclass[11pt]{article}
\usepackage{times}
\begin{document}

Consider the algorithm \textsf{heapify} below.

Consider the algorithm $\mathsf{heapify}$ below.

\end{document}

This gives me the following output.

sans-serif fonts

The first one is clearly ugly: the algorithm name's x-height is too big compared to the times text. The second line looks better to me but at the expense of using math mode for something that's "morally" text. This not only messes up spacing in pseudocode but it also doesn't work when your next algorithm is called make-heap; I don't consider $\mathsf{make}\textsf{-}\mathsf{heap}$ a solution.

Is there a simple way to set the \textsf font to match the \mathsf ones?

Note: using the default sans font (cmss?) together with Times and setting algorithm names in sans-serif within a text block are both decisions which are not mine to question.

Best Answer

You can achieve your objective as follows:

  • Don't load the times package, as it is deprecated. Load the package mathptmx instead. (Or, if you prefer, load the packages newtxtext and newtxmath.)

  • Load the helvet package with the option Scaled. In my opinion, the default amount of scaling that's applied isn't quite right for use with the Times text font if you want the x-heights of the serif and sans-serif letters to line up. I'd therefore use the option Scaled=0.86.

Incidentally, the font employed by mathsf in your example is not Helvetica but Computer Modern Sans Serif.

enter image description here

\documentclass[11pt]{article}
\usepackage{mathptmx}
\usepackage[scaled=0.86]{helvet}
\begin{document}
Consider the algorithm \textsf{heapify} below.

Consider the algorithm $\mathsf{heapify}$ below.
\end{document}

Addendum: I had assumed -- possibly erroneously -- that because you loaded the package times, you wanted to use Helvetica as the document's sans serif font. If this assumption is incorrect, i.e., if you simply want to use Computer Modern Sans Serif (CMSS) along with Times New Roman (TNR), don't load the helvet package -- and definitely don't load the times package since it sets up Helvetica as the sans serif font. It so happens that the x-heights of TNR and CMSS are fairly similar; there is hence no need to scale CMSS to make it "work" alongside TNR.

Related Question