1

I need to write some pseudocode and am using the IEEE template. However, the guidelines say that algorithmic should be contained in a figure environment and that I am not supposed to use the algorithm package see here.

So far no problem just put everything in figure instead.

\begin{figure}
\begin{algorithmic}[1]
\item[\textbf{Input:}] some input 
\item[\textbf{Output:}] Some output
\STATE $P \gets 1$
\STATE $X \gets 2$
\STATE \RETURN$X + P$
\end{algorithmic}
\caption{Algorithm that does stuff}
\label{MagicalAlg}
\end{figure}

The problem is that this gives me a caption reading Fig. 1. Algorithm that does stuff and I would like it to read Alg. 1. Algorithm that does stuff and not be numbered with the figures but separately.

Thanks for the help.

Edit: I have found a somewhat ugly workaround: I define a new environment based on the figure environment and rename the \figurename to Alg.. Then I needed to introduce two more counters, one as a placeholder(PlaceHolder) and one for keeping track of the actual numbering of the algorithms(BestAlgorithm). Otherwise the it would number algorithms and figure together.

\newcounter{BestAlgorithm}
\newcounter{PlaceHolder}

\newenvironment{BestAlgorithm}
{\setcounter{PlaceHolder}{\value{figure}} 
 \setcounter{figure}{\value{BestAlgorithm}}\begin{figure} 
\renewcommand{\figurename}{Alg.} }
{\end{figure} \setcounter{figure}   
{\value{PlaceHolder}} \addtocounter {BestAlgorithm} {1}}

After defining this in the beginning of the document, I can use BestAlgorithm instead of the figure environment.

Is there a nicer way to assign a counter to a new environment?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.