# Combining letters and numbers in numbering algorithms by using the algorithm2e package

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 Answer

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} • 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. – Salivan Jul 22 '20 at 13:17
• 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. – epR8GaYuh Jul 22 '20 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. – Salivan Jul 22 '20 at 15:40