# Two algorithm counters for different types of algorithms

I want to create two separate algorithm counters in Latex. The first one is for my main algorithms, the second one for subroutines.

In particular, I now have the following algorithms (in order):

Algorithm 1

Algorithm 2

Algorithm 3

This I want to change into (in order):

Algorithm 1

Subroutine 1 (so different name and different counter)

Algorithm 2

How can this be done?

I use:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

\begin{document}

\begin{algorithm}[H]
\caption{NameForAlgo1}
\label{}
\begin{algorithmic}[1]

\end{algorithmic}
\end{algorithm}

\begin{algorithm}[H]
\caption{NameForSubRoutine1}
\label{}
\begin{algorithmic}[1]

\end{algorithmic}
\end{algorithm}

\begin{algorithm}[H]
\caption{NameForAlgo2}
\label{}
\begin{algorithmic}[1]

\end{algorithmic}
\end{algorithm}

\end{document}

• What package do you use for formatting your algorithms? There are many options out there, each of which require different approach to a solution. Aug 16 '14 at 14:59
• I use the following to create my algorithms: \begin{algorithm}[H] \caption{Name} \label{} \begin{algorithmic}[1] \end{algorithmic} \end{algorithm}
– dro
Aug 16 '14 at 15:01
• So is it algorithmicx (which provides algorithmic) or algorithms's algorithmic? Please, before you answer in comment, consider adding a minimal working example (MWE) to your post via an edit. Click on the MWE link and read the post... Aug 16 '14 at 15:03
• I hope this MWE is sufficient to answer my question.
– dro
Aug 16 '14 at 15:15

algorithms is based on the package float, so one really simple fix would be to just declare a new float for subroutines in the preamble. To make sure they show up in the List of Algorithms you should probably make sure they go to file with a loa extension. You should also probably make sure you have a ToC sectioning command for subroutines, since I don't think those are automatically created when \newfloat is used.
\newfloat{subroutine}{htbp}{loa} \floatname{subroutine}{Subroutine} \makeatletter\newcommand\l@subroutine{\@dottedtocline{1}{1.5em}{2.3em}}\makeatother
Before you begin the document, [edit: and then use \begin{subroutine}\end{subroutine} in place of \begin{algorithm} where needed, ] and I think you should be fine.