5

A journal has asked me to change the font of my algorithm to Courier New. I'm able to change all except the keywords (if, then, else, etc.). My best solution looks like this:

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
    \begin{algorithm}[H]
        {{\fontfamily{pcr}
            \If {{\fontfamily{pcr}\selectfont condition}}
        }}
    \end{algorithm}
\end{document}

1 Answer 1

2

You can set each of the algorithm components individually (through settings like \SetKwStyle, \SetArgSty, \SetDataSty, ...), or change the font at the start of every algorithm automatically by adjusting \textnormal:

enter image description here

\documentclass{article}

\usepackage{algorithm2e,etoolbox}
\AtBeginEnvironment{algorithm}{\let\textnormal\ttfamily}

\begin{document}

\begin{algorithm}[H]
  \If {condition}{true clause}
\end{algorithm}

\end{document}

etoolbox was used to tap into \begin{algorithm}.

2
  • Hi, could you please give me an example of how to use \SetKwStyle to change the default font? I tried many ways but failed. Many thanks!! Commented Apr 5, 2017 at 7:29
  • 2
    @JustinCivi: You can try \SetKwSty{texttt} (not \SetKwSty{\texttt}).
    – Werner
    Commented Apr 6, 2017 at 2:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .