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.
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 packagemathptmx
instead. (Or, if you prefer, load the packagesnewtxtext
andnewtxmath
.)Load the
helvet
package with the optionScaled
. In my opinion, the default amount of scaling that's applied isn't quite right for use with theTimes
text font if you want the x-heights of the serif and sans-serif letters to line up. I'd therefore use the optionScaled=0.86
.Incidentally, the font employed by
mathsf
in your example is not Helvetica butComputer Modern Sans Serif
.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 thehelvet
package -- and definitely don't load thetimes
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.