The following MWE is self-explanatory:
\documentclass{beamer}
\usepackage[ruled]{algorithm2e}
\begin{document}
\begin{frame}
\begin{algorithm}[H]
\label{algoone}
\caption{Algorithm for solving my problem}
\While{condition}{
iterate;
}
\end{algorithm}
\end{frame}
\begin{frame}
Here is a faster version of Algorithm \ref{algoone}.
\begin{algorithm}[H]
\label{algotwo}
% Uncommenting the following line produces an error:
% \caption{Faster version of Algorithm \ref{algoone}}
\While{condition}{
iterate faster;
}
\end{algorithm}
\end{frame}
\end{document}
I have two algorithms on different slides of a Beamer presentation. I would like to refer to the other algorithm by its number in the caption to another algorithm. That is, the second caption should read "Faster version of Algorithm 1."
This works fine in an article environment. The textual references also work fine. However, including \ref{} in an algorithm caption in Beamer produces ! Argument of \@caption has an extra }.
How can I obtain the desired behavior?
(Placing the label after the caption, as suggested here, does not work.)
\caption[]{...}or\protect\ref{...}– MadyYuvi Oct 29 '21 at 05:28