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?
\documentclass{article}
\usepackage{algpseudocode,algorithm}
\makeatletter
\algrenewcommand\ALG@beginalgorithmic{\ttdefault}
\makeatother
\begin{document}
\begin{algorithm}
\caption{Euclid’s algorithm}\label{euclid}
\begin{algorithmic}[1]
\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$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is $b$}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
\ttfamily
as suggested by @Zarko is certainly a good solution in most ways, I've just checked thecmtt
fonts available in TeX Live. Someone has providedcmbtt
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 ofcmtt
, and the only way I could do it well was to create a lighter version of the originalcmtt
and then a bolder version; that was in the days when bitmap fonts were still the standard.