求一个用algorithmic包写伪代码的示例,包括input、for、if,不能使用algorithm,algorithm2e
\documentclass{IEEEtran}
\usepackage[commentColor=black]{algpseudocodex}
\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}
\usepackage[most]{tcolorbox}
\tcbset{
standard jigsaw,
sharp corners=all,
colframe=black,
opacityback=0,
boxsep=0pt,
boxrule=0.5pt,
top=5pt,
bottom=5pt,
left=5pt,
right=5pt,
beforeafter skip=10pt
}
\begin{document}
\begin{figure}
\rule{\linewidth}{1pt}
\begin{algorithmic}[1]
\Require something
\Ensure something
\State $sum\gets 0$
\LComment{The next two lines increment both $x$ and $y$.}
\For{$i\gets 1, n$}
\State $sum\gets sum+i$ \Comment{Increment $x$.}
\EndFor
\While{$i\gets 1, n$}
\State $sum\gets sum+i$
\EndWhile
\If{$quality\ge 9$}
\State $a\gets perfect$
\ElsIf{$quality\ge 7$}
\State $a\gets good$
\ElsIf{$quality\ge 5$}
\State $a\gets medium$
\ElsIf{$quality\ge 3$}
\State $a\gets bad$
\Else
\State $a\gets unusable$
\EndIf
\end{algorithmic}
\rule[.8em]{\linewidth}{1pt}
\caption{XXX}
\label{XXX}
\end{figure}
\begin{figure}
\begin{tcolorbox}
\begin{algorithmic}[1]
\Require something
\Ensure something
\State $sum\gets 0$
\LComment{The next two lines increment both $x$ and $y$.}
\For{$i\gets 1, n$}
\State $sum\gets sum+i$ \Comment{Increment $x$.}
\EndFor
\While{$i\gets 1, n$}
\State $sum\gets sum+i$
\EndWhile
\If{$quality\ge 9$}
\State $a\gets perfect$
\ElsIf{$quality\ge 7$}
\State $a\gets good$
\ElsIf{$quality\ge 5$}
\State $a\gets medium$
\ElsIf{$quality\ge 3$}
\State $a\gets bad$
\Else
\State $a\gets unusable$
\EndIf
\end{algorithmic}
\end{tcolorbox}
\caption{XXX}
\label{XXX1}
\end{figure}
\end{document}
没看懂问题是什么,看看这个代码:
\documentclass{IEEEtran}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}[H]
\caption{Algorithm for ...}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE in
\ENSURE out
\\ \textit{Initialisation} :
\STATE first statement
\\ \textit{LOOP Process}
\FOR {$i = l-2$ to $0$}
\STATE statements..
\IF {($i \ne 0$)}
\STATE statement..
\ENDIF
\ENDFOR
\RETURN $P$
\end{algorithmic}
\end{algorithm}
\end{document}
就是不要用usepackage{algorithm}
@u57573 不用就是不要caption外面的环境就好了。没什么影响呀。