Procedure Algorithm in Latex

I would like to create an algorithm as follows.

The code in latex is as follows.

\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}


However the code does not work. Could anyone help me, please?

Thank you.

• Why do you mingle two packages? Commented Mar 1, 2023 at 12:17

\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}


• Hi @clara, when I applied the given code, the result is on 1 liner. I provided in the question page, thank you. Commented Mar 1, 2023 at 13:30
• @NicholasTI Work well on TeX Live 2022. You can try it on Overleaf. If there is no problem, you need to update your TeX Live. Commented Mar 1, 2023 at 13:34
• Hi @clara, noted. By the way, is there any way to delete the black line in the printed algorithm? Thank you. Commented Mar 2, 2023 at 1:08
• @NicholasTI I have answered in tex.stackexchange.com/questions/676987 Commented Mar 2, 2023 at 1:57