我的算法分为两个阶段:
(1)For循环,(2)if条件
我的以下脚本出现错误:
\documentclass[conference]{IEEEtran}
\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{algorithmic}
\usepackage{algpseudocode}
\usepackage{amsmath}
\usepackage{varwidth}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\begin{document}
\begin{algorithm}
\begin{algorithmic}
\caption{Pseudo-code }
\Input{ X}
\Output{Y}
\ForEach {$X \in \mathcal Y$}{
$Z \gets \text U$\;
}
$T \gets R$\;
\If {$T\geq G$}
\State $T\gets 0$
\Else
\State $T\gets 1$
\EndIf
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
我不会混合algorithmic
和algorithm2e
。以下工作正常:
\documentclass[conference]{IEEEtran}
\usepackage[linesnumbered,ruled]{algorithm2e}
%\usepackage{algorithmic}
\usepackage{algpseudocode}
\usepackage{amsmath}
\usepackage{varwidth}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\begin{document}
\begin{algorithm}
\caption{Pseudo-code}
% \begin{algorithmic}
\Input{X}
\Output{Y}
\ForEach {$X \in \mathcal{Y}$}{
$Z \gets \mathrm{U}$\;
}
$T \gets R$\;
\eIf {$T \geq G$}{
$T\gets 0$\;
}{
$T\gets 1$\;
}
% \end{algorithmic}
\end{algorithm}
\end{document}