3

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

3

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

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

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

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.