Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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

share|improve this answer
    
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 0: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 0: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. –  Axel Sommerfeldt May 24 '12 at 5:26

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.