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


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
    May 21 '15 at 4:52
  • @okkhoy: You should mention that you're using algorithm2e... That makes a difference.
    – Werner
    May 21 '15 at 5:27
  • Thanks @Werner, sorry that I missed an important piece of information. My bad.
    – okkhoy
    May 21 '15 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
    May 21 '15 at 4:51
  • The packaged where the algorithm environment was defined wasn't loaded. May 21 '15 at 14:06

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.