How to use algorithm2e in IEEE trans template
This article mainly records how to use it in the IEEE trans template algorithm2e
to avoid stepping on the pit and not finding a solution.
Table of contents
1. Comment out the comment
Before importing the algorithm2e package, annotate unnecessary packages, otherwise errors will always be reported, and the reason cannot be found. The packages that need to be annotated include the following two:
\usepackage{
algorithm}
\usepackage{
algorithmic}
If you comment out the above two packages, when you import the algorithm2e package again, it will conflict and keep reporting errors.
2. Import the algorithm2e package
Use the following lines to import the algorithm2e package, and be careful to write the following 4 lines of code completely. You can’t just write the first line to import the package, but also add the following 3 lines, otherwise an error will be reported.
% \usepackage[ruled,norelsize,vlined,linesnumbered]{
algorithm2e}
% \makeatletter
% \newcommand{
\removelatexerror}{
\let\@latex@error\@gobble}
% \makeatother
3. Use the algorithm2e package to write the algorithm
Writing the algorithm with the following code is to put the algorithm in \begin{figure} \end{figure}
the middle. Attach a simple example code:
\begin{
figure}[!t]
\removelatexerror
\begin{
algorithm}[H]
\caption{
multiobjective DE}
initialize population $P = \left \{
X_{
1}, ... , X_{
N} \right \} $\;
\For( \emph{
Evolutionary loop}){
$g := 1$ to $G_{
max}$}
{
Do things \;
Trim the population to size $N$ using nondominated sorting and diversity estimation \;
}
\end{
algorithm}
\end{
figure}
The effect of the above algorithm after running is as follows:
Of course, you can also add line numbers to the algorithm, or important content such as Input and Output, you can refer to the following code:
\begin{
figure}[!t]
\removelatexerror
\begin{
algorithm}[H]
\KwIn{
this text}
\KwOut{
how to write algorithm with \LaTeX2e }
initialization\;
\While{
not at end of this document}{
read current\;
\Repeat{
this end condition}{
do these things\;
}
\eIf{
understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
\Do{
this end condition}{
do these things\;
}
}
\caption{
How to write algorithms}
\end{
algorithm}
\end{
figure}
references