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}
Best Answer
algorithms
is based on the packagefloat
, 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 aloa
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.But if you add
\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.