[Tex/LaTex] Algorithm2e: What is the recommended method to change the caption of ONE algorithm

algorithm2ecaptions

I want to read the caption of one of my algorithms typeset by algorithm2e to read Listing instead of the default algorithm.

What is the recommended/best way to achieve this?

I actually have a working solution, but I'm not sure if this is a good way to do it and wonder if it might come back and bite me some place: simply use algorithmcfname to change the caption to Listing and then change it back to Algorithm after the potion that should use a different caption, like so:

\renewcommand*{\algorithmcfname}{Listing}
\begin{algorithm}
....
\end{algorithm}
\renewcommand*{\algorithmcfname}{Algorithm}

Best Answer

You can use \SetAlgorithmName{Listing} inside the algorithm environment. Unfortunately, \autoref is going to translate always to algorithm #.

\documentclass{article}
\usepackage{algorithm2e}


\begin{document}

    \begin{algorithm}
        test
        \caption{algo 1}
    \end{algorithm}


    \begin{algorithm}
        \SetAlgorithmName{Listing}
        test
        \caption{algo 2}
    \end{algorithm}

    \begin{algorithm}
        test
        \caption{algo 3}
    \end{algorithm}
\end{document}

enter image description here

Related Question