2

For my Appendix section, I would like to reset the numbering of my equations and algorithms, and I would like to add the letter "A" just before the numbers. I do achieve this goal for my equations by adding the following lines to the beginning of my Appendix. How can I do the same thing for my algorithms? I am using the algorithm2e package.

\setcounter{equation}{0}
\renewcommand{\theequation}{A\arabic{equation}}
1
  • The question also handles the case of Algorithm numbering in appendices Commented May 21, 2023 at 18:09

1 Answer 1

4

From examining the package source code, algocf and \thealgocf are your friend.

Example:

\documentclass{article}

\usepackage[linesnumbered,lined,boxed,commentsnumbered]{algorithm2e}

\begin{document}

\begin{algorithm}[H]
    \SetAlgoLined
    \KwData{this text}
    \KwResult{how to write algorithm with \LaTeX2e }

    initialization\;
    \While{not at end of this document}{
        read current\;
        \eIf{understand}{
            go to next section\;
            current section becomes this one\;
        }{
            go back to the beginning of current section\;
        }
    }
    \caption{How to write algorithms}
\end{algorithm}

\appendix

\setcounter{algocf}{0}
\renewcommand{\thealgocf}{A\arabic{algocf}}

\begin{algorithm}[H]
    \SetAlgoLined
    \KwData{this text}
    \KwResult{how to write algorithm with \LaTeX2e }

    initialization\;
    \While{not at end of this document}{
        read current\;
        \eIf{understand}{
            go to next section\;
            current section becomes this one\;
        }{
            go back to the beginning of current section\;
        }
    }
    \caption{How to write algorithms}
\end{algorithm}

\end{document}

Example output

3
  • Thanks, @epR8GaYuh! Your formula resets the numbering and puts the letter "A" before numbers. The only issue is that when I refer to the Appendix algorithm in the main body, it does not show the new numbering. It keeps showing the number that the algorithm used to get before using the formula. Commented Jul 22, 2020 at 13:17
  • 1
    I cannot reproduce this on my device (using TeX Live 2017 on Ubuntu 18.04). \ref{algorithm1} \ref{algorithm2} (with the respective labels) leads to 1 A1 for me, as well as with \autoref. Commented Jul 22, 2020 at 13:37
  • Thanks for confirming it. I am using a journal-specific .cls file that imposes some settings and that could be the reason why we are getting different results from the \ref command. Commented Jul 22, 2020 at 15:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.