[Tex/LaTex] Start algorithm step numbering not at 1

algorithmicalgorithms

I have part of an algorithm that branches off from another algorithm, so I would like to present the numbering of the steps starting from that number instead of 1. Right now, I have it set up as follows:

\begin{algorithm}
    \begin{algorithmic}[1]
    \STATE Step 5
    \STATE Step 6
    \end{algorithmic}
\end{algorithm}

I've found a few things about how to change line numbering, but couldn't make anything affect the step numbering.

Best Answer

Store the counter and restore it using TeX's \label-\ref system and the support of refcount:

enter image description here

\documentclass{article}

\usepackage{algorithm,algorithmic,refcount}

\begin{document}

\begin{algorithm}
  \begin{algorithmic}[1]
    \STATE First step
    \STATE Second step
    \STATE Third step
    \STATE Fourth step \label{alg:last-step}
  \end{algorithmic}
\end{algorithm}

\begin{algorithm}
  \begin{algorithmic}[1]
    \setcounterref{ALC@line}{alg:last-step}
    \STATE Fifth step
    \STATE Sixth step
  \end{algorithmic}
\end{algorithm}

\end{document}

Note that algorithmicx provides \algsave and \algrestore, specifically for this purpose.