[Tex/LaTex] How to rename “Data” (from \KwData{}) and “Result” (from \KwResult{}) in \begin{algorithm} to something else

algorithms

Say I have the following code:

\begin{algorithm}
\KwData{my data}
\KwResult{my output}
my algorithm
\caption{my caption}
\end{algorithm}

It will produce something like this:


Algorithm 1: my caption
Data: my data
Result: my output
1 my algorithm


I want to rename 'Data' and 'Result' to something else.

How do I do that?

Thank you.

Best Answer

You can change the labels either globally (in the document preamble) or locally (in the algorithm environment) using \SetKwInput.

\documentclass{article}
\usepackage{algorithm2e}

% global change
\SetKwInput{KwData}{The data}
\SetKwInput{KwResult}{The result}

\begin{document}

\begin{algorithm}
\KwData{my data}
\KwResult{my output}
my algorithm
\caption{my caption}
\end{algorithm}

\begin{algorithm}
% local change
\SetKwInput{KwData}{Abbott}
\SetKwInput{KwResult}{Costello}
\KwData{my data}
\KwResult{my output}
my algorithm
\caption{my caption}
\end{algorithm}

% the local change has been reverted

\begin{algorithm}
\KwData{my data}
\KwResult{my output}
my algorithm
\caption{my caption}
\end{algorithm}

\end{document}

enter image description here