Beamer 不允许我添加算法环境

Beamer 不允许我添加算法环境

我正在编写一个投影仪演示文稿,我一直尝试向其中添加算法,但没有成功。

我有:

\begin{frame}{Proposed Solutions}{Curve Projection}
\begin{block}{}
    Ellipses are implicit surfaces, we can use their gradient to our advantage!
\end{block}

\begin{minipage}{0.45\textwidth}
    \begin{algorithmic}[1]

    \end{algorithmic}
\end{minipage}
\end{frame}  

编译失败并出现错误

出了点问题,可能缺少 \item。\end{frame}

删除算法环境可以让它编译,

向算法环境添加任何内容。例如:

\begin{frame}{Proposed Solutions}{Curve Projection}
\begin{block}{}
    Ellipses are implicit surfaces, we can use their gradient to our advantage!
\end{block}

\begin{minipage}{0.45\textwidth}
    \begin{algorithmic}[1]
    \Procedure{Find\_distance}{$p_1, p_2$}
    \end{algorithmic}
\end{minipage}
\end{frame} 

无法解决问题

答案1

如果框架内有易碎内容,则需要fragile框架选项。

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{algpseudocode}

\begin{document}

\begin{frame}[fragile]{Proposed Solutions}{Curve Projection}
\begin{block}{}
    Ellipses are implicit surfaces, we can use their gradient to our advantage!
\end{block}

\begin{minipage}{0.45\textwidth}
    \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
   \State $r\gets a\bmod b$
   \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
   \EndWhile\label{euclidendwhile}
   \State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
    \end{algorithmic}
\end{minipage}
\end{frame} 


\end{document}

在此处输入图片描述

相关内容