# Customizing pseudo-algorithms in algorithm2e package

If I have a pseudo-algorithm in Latex that looks like this:

With source code below.

\usepackage[ruled, vlined]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\DontPrintSemicolon
$\mathbf{D}_{obs}(f,Nx,Ny,x,y)\leftarrow \mathbf{D}_{obs}(t,Nx,Ny,x,y)$ by 1-D forward FFT\;
$\mathbf{D}_0\leftarrow\mathbf{D}_{obs}$\;
\For{$f\leftarrow 1,2,\dots,F$}{
\For{$f\leftarrow 1,2,\dots,F$}{
$\mathbf{D}^f_n \leftarrow a_n\mathbf{D}^f_{obs} + (1 - a_n)\mathcal{SF}_{d}\mathbf{D}^f_{n-1} + (1 - \mathcal{S})\mathcal{F}_{d}\mathbf{D}^f_{n-1}$\;
\If{$\left\|\mathbf{D}^f_n - \mathbf{D}^f_{n-1}\right\|_F^2\leq\epsilon$}{
\textbf{return} $\mathbf{D}^f_n$\;
}
\textbf{return} $\mathbf{D}^f_{n_{max}}$\;
}
\textbf{return} $\mathbf{D}_{recovered}$\;
}
$\mathbf{D}_{recovered}(t,Nx,Ny,x,y)\leftarrow \mathbf{D}_{recovered}(f,Nx,Ny,x,y)$ by 1-D inverse FFT\;

\caption{Construction Heuristic - Control 4-6}
\label{algorithm_2}
\end{algorithm}
\end{document}


How can I change the bold name "Algorithm 2" into something else, like "Function 2"? Right now it automatically names all algorithm blocks and just adds a number. I found this thread but in this case it just changes ALL algorithm names. Sometimes I want to write "Function" and sometimes "Algorithm".

You can use \renewcommand{\algorithmcfname}{Function} to change it.

\documentclass{article}
\usepackage[ruled,vlined]{algorithm2e}
\begin{document}

\begin{algorithm}
$\mathbf{D}_0\leftarrow\mathbf{D}_{obs}$
\caption{Construction Heuristic - Control 4-6}
\label{algorithm_2}
\end{algorithm}

\begin{algorithm}
\renewcommand{\algorithmcfname}{Function}
$\mathbf{D}_0\leftarrow\mathbf{D}_{obs}$
\caption{Construction Heuristic - Control 4-6}
\label{algorithm_2}
\end{algorithm}

\begin{algorithm}
$\mathbf{D}_0\leftarrow\mathbf{D}_{obs}$
\caption{Construction Heuristic - Control 4-6}
\label{algorithm_2}
\end{algorithm}

\end{document}


• How can I suppress the numbers? For example if I only want to write 'Algorithm' and not 'Algorithm 1' ? Sep 20, 2022 at 10:07
• @Parseval Add \renewcommand{\thealgocf}{}\addtocounter{algocf}{-1} in algorithm environment. Sep 20, 2022 at 11:05
• You're the MVP. Thanks! Sep 20, 2022 at 11:09