
다음과 같은 알고리즘을 만들고 싶습니다.
라텍스의 코드는 다음과 같습니다.
\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}