# How to number the algorithms (some algorithms are put in a group)?

I want to write some groups of algorithms. For example, there are 2 groups and 2 related algorithms in each group.

I do not know how to number every algorithm in this case (like 1.1.1, 1.1.2, 3.1.1, 3.1.2; the format is:

number of section. number of group in the section. number of algorithm in the group.

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmic}
\setlength{\intextsep}{2pt}

\begin{document}

\section{A}
There is the first group of algorithm
\begin{figure*}[htbp]
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$A_{1}\left( x_{1} \right)$}
\STATE $y_{1} \leftarrow f\left( x_{1} \right)$
\RETURN $y_{1}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$A_{2}\left( x_{2} \right)$}
\STATE $y_{2} \leftarrow f\left( x_{2} \right)$
\RETURN $y_{2}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{figure*}

Blah, blah, blah...
\section{B}
Blah, blah, blah...
\section{C}
There is the second group of algorithm
\begin{figure*}[htbp]
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$C_{1}\left( x_{1} \right)$}
\STATE $y_{1} \leftarrow f\left( x_{1} \right)$
\RETURN $y_{1}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$C_{2}\left( x_{2} \right)$}
\STATE $y_{2} \leftarrow f\left( x_{2} \right)$
\RETURN $y_{2}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{figure*}
\end{document}


Added counter algroup and set counters to reset to zero automatically.

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\setlength{\intextsep}{2pt}

\newcounter{algroup}[section]
\renewcommand{\thealgroup}{\thesection.\arabic{algroup}}
\counterwithin{algorithm}{algroup}
\renewcommand{\thealgorithm}{\thealgroup.\arabic{algorithm}}

\begin{document}

\section{A}
There is the first group of algorithm
\stepcounter{algroup}
\begin{figure*}[htbp]
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$A_{1}\left( x_{1} \right)$}
\State $y_{1} \leftarrow f\left( x_{1} \right)$
\Return $y_{1}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$A_{2}\left( x_{2} \right)$}
\State $y_{2} \leftarrow f\left( x_{2} \right)$
\Return $y_{2}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{figure*}

Blah, blah, blah...
\section{B}
Blah, blah, blah...
\section{C}
There is the second group of algorithm
\stepcounter{algroup}
\begin{figure*}[htbp]
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$C_{1}\left( x_{1} \right)$}
\State $y_{1} \leftarrow f\left( x_{1} \right)$
\Return $y_{1}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}[t]{.49\textwidth}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\caption{$C_{2}\left( x_{2} \right)$}
\State $y_{2} \leftarrow f\left( x_{2} \right)$
\Return $y_{2}$
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{figure*}
\end{document}


• What if there is an only one algorithm in chapter 2 whose number should be 2.1? Oct 18 '18 at 5:22
• The only way I know is that I write "\renewcommand{\thealgorithm}{\thealgroup}" before that algorithm. Oct 18 '18 at 5:26