14

In this example I would like to reduce the pseudocode font size, but only for this slide while keeping the others in the default font size. How can I do that?

15

The simplest way would be to add \small, \footnotesize, \scriptsize, or \tiny immediately after the beginning of the algorithm environment. This changes the size of everything inside the environment (except for the caption), and nowhere else.

Edited to add: This will apparently leave the size of the line-numbers and of the caption unchanged. In order to change the size of the line-numbers for the algorithm, add the command \algsetup{linenosize=<size>} just inside the algorithm environment, where <size> is again something like \small, \footnotesize, etc. Note that the default is to have line-numbers somewhat smaller than the surrounding text: if you want the appearance to be somewhat similar to algorithms elsewhere in your document, you should also choose a smaller size for the line-numbers than the algorithm body.

I am not sure how best to modify the size of the caption, unfortunately.

Example document.

\documentclass{beamer}
\usepackage{algorithmic,algorithm2e,float}
\begin{document}
\begin{frame}[fragile]
\begin{algorithm}[H]
  \algsetup{linenosize=\tiny}
  \scriptsize
  \begin{algorithmic}[1]
    \FOR{this algorithm only}
      \STATE all of the text in a smaller size of typeface
    \ENDFOR
    \medskip
  \end{algorithmic}
  \caption{an algorithm with smaller typeface}
\end{algorithm}

\bigskip

some text outside of the environment

\bigskip

\begin{algorithm}[H]
  \begin{algorithmic}[1]
    \FOR{all other algorithms}
      \STATE everything normally unless otherwise modified
    \ENDFOR
    \medskip
  \end{algorithmic}
  \caption{an algorithm with normal typeface}
\end{algorithm}
\end{frame}
\end{document}

Result.

Algorithms with different sizes of typeface

  • great! last question, how can we change the caption text size? – Open the way Aug 26 '11 at 10:53
  • @flow: Unfortunately, I can't figure out a graceful way to do so. I just found out that my original answer also did not modify the size of the line-numbers: I've revised my answer to describe how to do that, at least. – Niel de Beaudrap Aug 26 '11 at 11:30
  • 1
    To change the caption put \renewcommand{\AlCapSty}[1]{\normalfont\scriptsize{\textbf{#1}}\unskip} in the environment. – Ulrike Fischer Aug 26 '11 at 11:57
  • A follow-up question on the line no size. Thanks a lot. tex.stackexchange.com/questions/145932/… – Sibbs Gambling Nov 20 '13 at 1:47
6

algorithm2e provides commands for customizing pseudocode font shape and size, algorithmic does that for line numbering. For example:

\usepackage{algorithm2e}
\SetAlFnt{\small}
\SetAlCapFnt{\large}
\SetAlCapNameFnt{\large}
\usepackage{algorithmic}
\algsetup{linenosize=\tiny}
  • 1
    Curious. When I compile this with a simple example, I get Undefined control sequence: \SetAlCapNameFnt, even though the command is clearly mentioned in the algorithm2e documentation. – Niel de Beaudrap Aug 26 '11 at 12:15
  • @Niel: perhaps update the package. – Stefan Kottwitz Aug 26 '11 at 12:31
  • just did, still have the problem. Quite odd. – Niel de Beaudrap Aug 26 '11 at 13:33

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.