Beamer and pseudocode
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}
- Load the required packages (for example
algorithmic
andalgorithm2e
oralgorithm
) - Use the
float
package withH
option for the floating algorithm environment option to get a fixed position - Use the
fragile
option for the frame if you get strange errors, it can fix problems with verbatim text and listings
Compilable example:
\documentclass{beamer}
\usetheme{Singapore}
\usepackage{algorithm2e}
\usepackage{algorithmic}
\usepackage{float}
\begin{document}
\section{Test}
\begin{frame}[fragile]
\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}