如何停止 Beamer 中的算法版本递增

如何停止 Beamer 中的算法版本递增

我有一个在 Beamer 中展示的算法。我想在它下面添加一些文本,这些文本出现在第二个转换中。但是,当出现下面的文本时,算法的字母版本会从 A 递增到 B。这是一个 MWE:

\documentclass{beamer}
\usepackage{algpseudocode,algorithm}
\usepackage{default}

\makeatletter \def\fps@algorithm{H} \makeatother
\renewcommand\thealgorithm{\Alph{algorithm}}

\begin{document}
\begin{frame}
\frametitle{Algorithm A}
\begin{algorithm}
    \caption{Code}
    \begin{algorithmic}[1]
        \State \Comment{\sc Empty array}
    \end{algorithmic}
\end{algorithm}
\vfill
\uncover<2->{
    Running time:   
    \[x^2\]
}
\end{frame}
\end{document}

看看它是如何成为算法A的,直到出现下面的“运行时间:”文字时,它才变成算法B。

我怎样才能让它停留在算法 A?

答案1

添加\resetcounteronoverlays{algorithm}到您的序言中:

覆盖

\documentclass{beamer}
\usepackage{algpseudocode,algorithm}
\usepackage{default}

\makeatletter \def\fps@algorithm{H} \makeatother
\renewcommand\thealgorithm{\Alph{algorithm}}
\resetcounteronoverlays{algorithm}

\begin{document}
    \begin{frame}
        \frametitle{Algorithm A}
        \begin{algorithm}
            \caption{Code}
            \begin{algorithmic}[1]
                \State \Comment{\sc Empty array}
            \end{algorithmic}
        \end{algorithm}
        \vfill
        \uncover<2->{
            Running time:   
            \[x^2\]
        }
    \end{frame}
\end{document}

相关内容