IEEEtran suggests do not use the algorithm floating environment. So I have been trying to mimic the original look of algorithm without success.
Here is my algorithm with algorithm floating environment:
\begin{algorithm}[!t]
\caption{my algorithm}
\label{alg: alg}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE input
\ENSURE output \\
\STATE $i\gets 10$
\IF {$i\geq 5$}
\STATE $i\gets i-1$
\ELSE
\IF {$i\leq 3$}
\STATE $i\gets i+2$
\ENDIF
\ENDIF
\end{algorithmic}
\end{algorithm}
However, if I use figure enviroment, the algorithm looks so ugly.
\begin{figure}[!t]
\caption{my algorithm}
\label{alg: alg}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE input
\ENSURE output \\
\STATE $i\gets 10$
\IF {$i\geq 5$}
\STATE $i\gets i-1$
\ELSE
\IF {$i\leq 3$}
\STATE $i\gets i+2$
\ENDIF
\ENDIF
\end{algorithmic}
\end{figure}
How can I generate the algorithm like the first one without violiting IEEEtran rules?
Here is the full code:
\documentclass[journal]{IEEEtran}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage[]{subfig}
\usepackage{stfloats}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{newtxtext, newtxmath}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{algorithm}[!t]
\caption{my algorithm}
\label{alg: alg}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE input
\ENSURE output \\
\STATE $i\gets 10$
\IF {$i\geq 5$}
\STATE $i\gets i-1$
\ELSE
\IF {$i\leq 3$}
\STATE $i\gets i+2$
\ENDIF
\ENDIF
\end{algorithmic}
\end{algorithm}
\lipsum[2]
\begin{figure}[!t]
\caption{my algorithm}
\label{alg: alg}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE input
\ENSURE output \\
\STATE $i\gets 10$
\IF {$i\geq 5$}
\STATE $i\gets i-1$
\ELSE
\IF {$i\leq 3$}
\STATE $i\gets i+2$
\ENDIF
\ENDIF
\end{algorithmic}
\end{figure}
\end{document}
Best Answer
algorithm
package was not allowed in the past. This is stated as follows in the filebare_adv.tex
.Now IEEE allows
algorithm
package. You can choose any journal template in IEEE-Template Selector. For example, IEEE Internet of Things Journal template, we open thebare_jrnl_new_sample4.tex
in it. You can see the following code.So, there is an example for you. I suggest you use
algpseudocodex
package. And I adjusted some styles according to what my editor modified. I hope it will be helpful to you.Default style