I would like to change the font of the algorithm package. It's currently using serif and I would like to try either sans serif or typewritter font. I have tried to use the following code (which I adapted from this link) by simply using the \ttdefault at line 5 but it does not work. How can I achieve my aim?



  \caption{Euclid’s algorithm}\label{euclid}
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of $a$ and $b$}
      \State $r \gets a \bmod b$
      \While{$r \not= 0$}\Comment{We have the answer if $r$ is 0}
        \State $a \gets b$
        \State $b \gets r$
        \State $r \gets a \bmod b$
      \State \textbf{return} $b$\Comment{The gcd is $b$}
  • There are several packages for algorithms, and I believe they all use bold for keywords. There are very few typewriter fonts available with a matching bold, so you would most likely lose that. Jul 27, 2019 at 19:33
  • Hello Barbara the aim is to convert the font family witouth loosing the bold for the keyword. Look at the answer of Zarko, he provided the right solution to my problem.
    – S12000
    Jul 27, 2019 at 19:54
  • While \ttfamily as suggested by @Zarko is certainly a good solution in most ways, I've just checked the cmtt fonts available in TeX Live. Someone has provided cmbtt fonts in several sizes, but only from Metafont source, so they will be bitmap fonts, an won't scale well. I'd be very happy to be shown to be wrong. (I once had to provide a bold version of cmtt, and the only way I could do it well was to create a lighter version of the original cmtt and then a bolder version; that was in the days when bitmap fonts were still the standard. Jul 27, 2019 at 20:45
  • OK I see. In fact in my case I am using xelatex with UbuntuMono as a typewritter font and it works very fine (no scaling issues).
    – S12000
    Jul 27, 2019 at 21:18
  • UbuntuMono sounds like it's designed for such things, I'm glad it works. (Since no specific font was indicated in the question, I just assumed CM.) Jul 27, 2019 at 21:55

1 Answer 1


If I'm not wrong, you should just use \usepackage{algpseudocode} because it seems to re-implement algorithms and it's the one that defines things like \State, etc.

There doesn't appear to be a single, simple way to change the font (maybe you should consider a different code package?).

The keywords in the code are defined in the package like this:


and you can change that to


You can make similar changes to some of the other keywords. This won't change the other text though, like "Euclid" and the text in the comments. You can change some of this by wrapping algorithm in a group with a font declaration.

\State $ABC$ ABC \Comment{this is a test}

But this still won't change the font for the math part. To change that font, either don't put it in math, or look at a package like mathastext that redefines the math fonts.

  • 3
    instead TeX \tt you should use LaTeX command \ttfamily :-)
    – Zarko
    Jul 27, 2019 at 19:40
  • Hello Zarko you are right if I replace \ttdefault by \ttfamily it works like a charm. I would use as a accepted answer. Could you please put your comment as answer?
    – S12000
    Jul 27, 2019 at 19:51
  • Hello Ethan, thanks a lot for all the explanations I understand more the background of the package now. However, I think the solution of Zarko is more simple.
    – S12000
    Jul 27, 2019 at 19:52

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.