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?

3
  • How about the answer here... does this help ? Commented Jan 17, 2019 at 12:57
  • See tex.stackexchange.com/questions/394825/… Commented Jan 17, 2019 at 16:50
  • So the guidelines say to use the figure environment. Why are you changing something that might end up being changed back by them anyway? Commented Jan 17, 2019 at 18:20

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.