
我正在嘗試使用 IEEE Access 網站上的範本來撰寫一篇論文。但我在編寫偽代碼時遇到了麻煩,因為他們的模板中沒有偽代碼範例。當我使用 ieeeaccess 範本時,我收到錯誤訊息,例如:
"額外\endcsname.\State",
“未定義的控制序列。\doWhile”,
「插入缺少 \endcsname。\State」。
而且,結果看起來並不像應有的那樣。例如,偽代碼中的所有行號均為零。另外,在編譯 .tex 檔案後,我得到了“require”和“ensure”,而不是“輸入”和“輸出”。
我是否缺少一些用戶包?
\documentclass{ieeeaccess}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage[section]{placeins}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{algorithmicx}
\algdef{SE}[DOWHILE]{Do}{doWhile}{\algorithmicdo}[1]{\algorithmicwhile\ #1}%
\begin{document}
\begin{algorithm}[H]
\caption{Algorithm 1}\label{Alg-Decap}
\begin{algorithmic}[1]
\Require{$(C,S_k)$}
\Ensure{ HashSession$(1,\underbar r,C)$ or HashSession$(0,\rho,C))$ }
\State $c\leftarrow$ Decode$(\underbar c)$
\State $c.(3f)\in\mathcal{R}/q$
\State $e\leftarrow $ (Rounded$(c.(3f))$ mod 3) $\in \mathcal{R}/3$
\State $e.(1/g)\in\mathcal{R}/3$
\State $r'\leftarrow$ Lift($e.(1/g)$) $\in\mathcal{R}/q$
\State $h.r'\in\mathcal{R}/q$
\State $c'\leftarrow$ Round$(h.r')$
\State $\underbar c'\leftarrow$ Encode$(c')$
\State $C'\leftarrow(\underbar c',$ HashConfirm$(\underbar r',\underbar h))$
\If{$C'==C$}
\State \textbf{return} HashSession$(1,\underbar r,C)$
\Else
\State \textbf{ return} HashSession$(0,\rho,C))$
\EndIf
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
您不得同時加載algorithmic
和algpseudocode
。由於您使用的是後者的語法,因此請刪除前者。
如果你想輸入和輸出,為他們定義基礎設施。
另外,不要進入和退出數學模式,也不要使用\underbar
, but \underline
。
\documentclass{ieeeaccess}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\algdef{SE}[DOWHILE]{Do}{doWhile}{\algorithmicdo}[1]{\algorithmicwhile\ #1}%
\algnewcommand\algorithmicinput{\textbf{Input:}}
\algnewcommand\algorithmicoutput{\textbf{Output:}}
\algnewcommand\Input{\item[\algorithmicinput]}
\algnewcommand\Output{\item[\algorithmicoutput]}
% no in and out of math mode!
\newcommand{\Fun}[1]{\mathrm{#1}}
\begin{document}
\begin{algorithm}[htp]
\caption{Algorithm 1}\label{Alg-Decap}
\begin{algorithmic}[1]
\Input{$(C,S_k)$}
\Output{$\Fun{HashSession}(1,\underbar r,C)$ or $\Fun{HashSession}(0,\rho,C))$}
\State $c\leftarrow \Fun{Decode}(\underbar c)$
\State $c.(3f)\in\mathcal{R}/q$
\State $e\leftarrow (\Fun{Rounded}(c.(3f))\bmod 3)\in \mathcal{R}/3$
\State $e.(1/g)\in\mathcal{R}/3$
\State $r'\leftarrow \Fun{Lift}(e.(1/g)) \in\mathcal{R}/q$
\State $h.r'\in\mathcal{R}/q$
\State $c'\leftarrow \Fun{Round}(h.r')$
\State $\underline{c}'\leftarrow \Fun{Encode}(c')$
\State $C'\leftarrow(\underline{c}', \Fun{HashConfirm}(\underline{r}',\underline{h}))$
\If{$C'==C$}
\State \textbf{return} $\Fun{HashSession}(1,\underline{r},C)$
\Else
\State \textbf{return} $\Fun{HashSession}(0,\rho,C))$
\EndIf
\end{algorithmic}
\end{algorithm}
\EOD
\end{document}