我想创建一个如下的算法。
latex中的代码如下。
\documentclass[journal]{IEEEtran}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
\caption{Sequence}
\begin{algorithmic}
\Procedure{Step I}
\State Do $U_LL$
\If{$n$ is odd number:}
\State Do $U_n$
\ELSE
\STATE Do $L_n$
\ENDIF
\Procedure{Step II}
\State For $\(i=1,\ldots,n:\)$
\If{$i \pmod{2}==1:$}
\State Do $L_i$
\ELSE
\STATE Do $U_i$
\ENDIF
\Procedure{Step III}
\State For \(i=1,\ldots,(n-1)\)
\If{$i \pmod{2}==1:$}
\State Do $U_i$
\ELSE
\STATE Do $L_i$
\ENDIF
\end{algorithmic}
\end{algorithm}
\end{document}
但是代码不起作用。有人能帮帮我吗?
答案1
\documentclass{IEEEtran}
\usepackage{algorithm}
\floatplacement{algorithm}{tbp}
\makeatletter
\newcommand{\algorithmname}{\ALG@name}
\renewcommand{\floatc@ruled}[2]{{\@fs@cfont #1} #2\par}
\makeatother
\usepackage[commentColor=black]{algpseudocodex}
\tikzset{algpxIndentLine/.style={draw=black}}
\algrenewcommand{\alglinenumber}[1]{\bfseries\footnotesize #1}
\algrenewcommand{\textproc}{\bfseries}
\begin{document}
\begin{algorithm}[h]
\caption{Sequence}
\begin{algorithmic}[1]
\Procedure{Step I}{}
\State Do $U_LL$
\If{$n$ is odd number}
\State Do $U_n$
\Else
\State Do $L_n$
\EndIf
\EndProcedure
\Procedure{Step II}{}
\For{$i=1,\ldots,n$}
\If{$i\bmod{2}==1$}
\State Do $L_i$
\Else
\State Do $U_i$
\EndIf
\EndFor
\EndProcedure
\Procedure{Step III}{}
\For{$i=1,\ldots,n-1$}
\If{$i\bmod{2}==1$}
\State Do $U_i$
\Else
\State Do $L_i$
\EndIf
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
\newpage
\begin{algorithm}[h]
\caption{Sequence}
\begin{algorithmic}[1]
\Statex \textbf{Step I}
\State Do $U_LL$
\If{$n$ is odd number}
\State Do $U_n$
\Else
\State Do $L_n$
\EndIf
\Statex \textbf{Step II}
\For{$i=1,\ldots,n$}
\If{$i\bmod{2}==1$}
\State Do $L_i$
\Else
\State Do $U_i$
\EndIf
\EndFor
\Statex \textbf{Step III}
\For{$i=1,\ldots,n-1$}
\If{$i\bmod{2}==1$}
\State Do $U_i$
\Else
\State Do $L_i$
\EndIf
\EndFor
\end{algorithmic}
\end{algorithm}
\end{document}