同时使用 algorithm、algpseudocode 和 algorithm2e 包

同时使用 algorithm、algpseudocode 和 algorithm2e 包

我必须同时使用algorithmalgpseudocodealgorithm2e包。我收到以下错误:

Missing number, treated as zero.

<to be read again> 
                   \ALG@b@2@EndIf@0 
l.79        \EndIf

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

有人知道如何处理这种情况吗?

\documentclass{article}

\usepackage{algorithm,algpseudocode}
\usepackage[algo2e]{algorithm2e}

\begin{document}

\begin{algorithm}
  \caption{Finding $z$ based on $w$}
  \begin{algorithmic}[1]
    \Function{ZWGameMA}{$\mathcal{A}$}  
      \State $v \in \{0,1\}^\lambda$ is a random input; 
      \State $\mathcal{S} \leftarrow \mathcal{A}(1^\lambda)$;
      \State $w \in \{0,1\}^\lambda$ is a random input;
      \If{${\cal S}(w)= vw$}
        \State $b = 1$;
      \Else
        \State $b = 0$;
        % I got error here, and I know it is because of the package conflict
      \EndIf
      \State Return $b$;
    \EndFunction
    \State /*On input $w$, an optimal $\mathcal{S}$ outputs a $z$ which maximizes $|\{v : z = vw\}|$.*/
  \end{algorithmic}
\end{algorithm}

\end{document}

相关内容