TransWikia.com

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

TeX - LaTeX Asked by Salivan on August 3, 2020

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}{Aarabic{equation}}

One 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}{Aarabic{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

Correct answer by epR8GaYuh on August 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP