7

I'm using the algorithms package in my document to get a floating environment for algorithms to live in.

\usepackage{algorithm}

I'm using the caption package to make the captions on my figures smaller.

\usepackage[font=footnotesize,bf]{caption}

The algorithms package ignores the caption package.

Is there any way to make it respond to caption's options?

Werner
  • 603,163
Richard
  • 5,723

2 Answers2

10

Use \captionsetup with algorithm option; since a comment suggest that you only want to have the label boldfaced and both label and text in \footnotesize size, it's enough to say:

\captionsetup[algorithm]{font=footnotesize}

since, by default, the label for algorithm captions is boldfaced.

\documentclass{article}
\usepackage{algorithm,algpseudocode}
\usepackage{caption}

\captionsetup[algorithm]{font=footnotesize}

\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}

enter image description here

Gonzalo Medina
  • 505,128
  • It may be useful to note that \floatname{algorithm}{\footnotesize Algorithm} controls the caption's label independent of its text. – Richard May 24 '12 at 00:10
  • 1
    @Richard: to control the label and the text separately, you can use the labelfont and textfont keys (or a combination of font and the other two). In your concrete example, it's enough to use \captionsetup[algorithm]{font={footnotesize}}, since by default the label will be boldfaced. – Gonzalo Medina May 24 '12 at 00:19
  • As an alternative to the solution above, one could redefine the caption style ruled. See caption package doc., section about interaction with the float package. –  May 24 '12 at 05:26
0

algorithm2e provides its own "do not float" [H] float specifier, setting the contents in a minipage if used this way. So one would have to use

\begin{algorithm}[H]
% <your algorithm here>
\end{algorithm}

under those conditions. A large amount of leg-work is done by the package at the start of the algorithm environment in order to set things up since it has its own interface (using \; to denote line-ends, otherwise known as a horizontal space in math-mode outside the environment).

soniya
  • 1