[Tex/LaTex] Beamer and pseudocode

beamerpseudocode

I am preparing a presentation with beamer from a previous paper written in latex. I want to insert in a slide the pseudocode

    \begin{algorithm}
\begin{algorithmic}[1]
\FOR{$i=1$ to $N$}
\FOR{$j=1$ to $JJJJ}
\STATE $energy[i*JJJ+j] =$ \\
$ interpolate(AAA[i*JJJ+j], ZZZ)$
\ENDFOR
\ENDFOR
\end{algorithmic}
\caption{pseudocode for the calculation of }
\label{alg:seq}
\end{algorithm}

but I get problems since the beamer document does not compile. I tried to use the same packages that in the latex document. I also tried to find examples through google but nothing. Could you tell me what is wron here or how could I add pseudocode in beamer )examples on the net, etc)?

Best Answer

The floating object algorithm doesn't behave well with beamer (which onviously disables floating objects). To prevent problems you can 1) use the H placement specifier for algorithm, or 2) drop the algorithm environment and use the \captionof command from the caption package if a caption is needed. The following example shows the first approach:

\documentclass[12pt]{beamer}
\usepackage{algorithm,algorithmic}

\begin{document}

\begin{frame}

\begin{algorithm}[H]
\begin{algorithmic}[1]
\FOR{$i=1$ to $N$}
\FOR{$j=1$ to $JJJJ$}
\STATE $energy[i*JJJ+j] =$ 
$ interpolate(AAA[i*JJJ+j], ZZZ)$
\ENDFOR
\ENDFOR
\end{algorithmic}
\caption{pseudocode for the calculation of }
\label{alg:seq}
\end{algorithm}
\end{frame}

\end{document}