# new caption type in captionof

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

\setcaptiontype{Algorithm}
\captionsetup{options=algorithm}
\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).

\documentclass{article}
\usepackage{algorithm2e,caption}
\begin{document}

\begin{algorithm}[H]
\caption{My algorithm}
\end{algorithm}

\noindent
\begin{minipage}{\linewidth}
\captionof{algocf}{My algorithm}
\end{minipage}

\end{document}

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

\documentclass{article}
\usepackage{float}
\usepackage{caption}
\newfloat{Algorithm}{htbp}{loa}
\begin{document}
\captionof{Algorithm}{test}
\end{document}

• 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. – John Kormylo May 21 '15 at 14:06