5

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.

4

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.

  • I don't see any mention of Helvetica in the question: doesn't the OP want Times + CMSS (scaled)? – Joseph Wright Oct 7 '14 at 8:50
  • That works for me. Just out of curiosity, is it possible to set the \textsf font to be the same as the math one (with textmode spacing/dashes etc.)? – Bristol Oct 7 '14 at 8:55
  • 1
    @JosephWright - The file times.sty contains the instruction \renewcommand{\sfdefault}{phv} -- Helvetica -- (along with, naturally, \renewcommand{\rmdefault}{ptm} -- Times Roman). I believe that the inability to scale Helvetica is one of the reasons why the times package is considered deprecated. – Mico Oct 7 '14 at 8:55
  • @Bristol - please see the addendum to my answer. – Mico Oct 7 '14 at 9:07
  • Thanks - loading times through mathptmx definitely looks better. My instructions were to use "11pt Times" for the body and "not change any fonts" - though Helvetica (loaded through the times package) seems to be what most people are using for algorithm names. We'll see if they accept (or even notice) CMSS too. – Bristol Oct 7 '14 at 10:08

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.