\captionof command from caption package allows caption for various floats. However we cannot use it to typeset an algorithm caption like: \captionof{Algorithm}{<Caption text>}. I tried the following without success.

\captionof{Algorithm}{My caption}

So my question is, can we define a new type to be used in \captionof command? If so how?

2 Answers 2


The type is different from what is typically used in the naming. In that regard, the algorithm environment typically use Algorithm as its name. algorithm2e is slightly different though; it uses algocf as the type, so you need to use

\captionof{algocf}{<caption of algorithm>}

Make sure the \captionof macro is used inside an environment (or group).

enter image description here


  \caption{My algorithm}

  \captionof{algocf}{My algorithm}

  • I tried this and it generates only the caption without the "type". I get the caption as follows. " : My algorithm ". Instead I wanted "Algorithm 1: My algorithm"
    – okkhoy
    Commented May 21, 2015 at 4:52
  • @okkhoy: You should mention that you're using algorithm2e... That makes a difference.
    – Werner
    Commented May 21, 2015 at 5:27
  • Thanks @Werner, sorry that I missed an important piece of information. My bad.
    – okkhoy
    Commented May 21, 2015 at 6:35

As to creating a new type, use \newfloat (or just \newcounter).

  • I used \newfloat and it worked! However, if you have an idea could you please explain why the default algorithm from algorithm2e package was not picked up?
    – okkhoy
    Commented May 21, 2015 at 4:51
  • The packaged where the algorithm environment was defined wasn't loaded. Commented May 21, 2015 at 14:06

You must log in to answer this question.

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