1

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.

1 Answer 1

2

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.

4
  • Actually it's ALG@line not ALC@line.
    – foobar
    Feb 17, 2018 at 17:25
  • @foobar: Why do you say that? Have you tried it?
    – Werner
    Feb 18, 2018 at 4:37
  • Yes. I tried with ALC@line and it didn't work. Changing it to ALG@line it was fine. Not sure, maybe different settings.
    – foobar
    Feb 18, 2018 at 13:44
  • @foobar: The algorithms bundle - that produces algorithmic.sty - has not been updated since 2009. You can search for ALC@line in algorithms.dtx. My guess is you may have a local (updated/variation) copy of algorithmic.sty.
    – Werner
    Feb 18, 2018 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.