# Algorithm in IEEE journal

Here is the template I use for the following journal. The algorithm is perfect in regular latex document as can be seen in: . I have problems with all the algorithm when inserting it to the template.

I use the following code:

\documentclass[10pt,journal,compsoc]{IEEEtran}
% *** MATH PACKAGES ***
%
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{algorithm}
\usepackage{textcomp}
\usepackage{filecontents}
\usepackage{microtype}
\usepackage{float}
\usepackage{booktabs,makecell,tabularx}
\usepackage{url}
\usepackage{booktabs}
\usepackage{subfigure}
\newcommand{\tvar}[2]{%
\mathrm{#1}_{\mathrm{#2}}%
}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{siunitx}
\usepackage[utf8]{inputenc}
\renewcommand{\thetable}{\arabic{table}}
\usepackage{etoolbox}
\usepackage{xparse}
\makeatletter
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\begin{document}
\begin{algorithm}
\caption{Esdfdfsy}
\label{alg:ALG1}
\begin{flushleft}
\textbf{OUTPUT:} Prediction of $W_{t_c}$ records
\end{flushleft}
\begin{algorithmic}

\ForAll {$i$=1 to $N$}
\Comment{fdasdfn fdas}
\State dfasdsf $afsddfs_i$  from $T_i$
\EndFor

\State Apply $HAT$ to  $\bigcup\limits_{i=1}^{F} W_{i}$ \Comment{IIIIII process -fdsdfsfsd}\\

\If { $wr < htr$ }          \Comment{Nfsddfssdfasdf  }
\State $s = 0$
\Else
\State $s = \floor {wr / htr}$
\EndIf
\State xxx = 0
\While {     $WYU_c \not=\O$ }
\State c = c + 1
\State Update $XXXXX$ with $W_{(dfsf2)-f}$

$\parallel$   \Comment{in parallel}
\\$Eadssad (W_{t_{c-1}})$ =  Predict ( dasda ($dasa8_{t_c-2,..,t_c-N-1}$ ) ) over $dsad_{t_c-1}$
$\parallel$
\\ $J48 (W_{t_{c-1}})$ = Predict ($J48_{t_{c-2}}$) over $W_{t_c-1}$     \Comment{This is done as part of the ensemble }

\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}

• Add the packages algpseudocode and algorithmicx in your preamble ... The order could be: \usepackage{algpseudocode} \usepackage{algorithm} \usepackage{algorithmicx}. This will solve the errors – koleygr Aug 13 '19 at 8:31
• Also you can change the while content like \While { $WYU_c \not=$\O } Because \O is not defined in math mode. – koleygr Aug 13 '19 at 8:33
• I get errors while adding the packages algpseudocode and algorithmicx – Avi Aug 13 '19 at 8:50
• Check the code in my answer please ... You possibly are loading in an incorrect order or added algorithm package twice etc. – koleygr Aug 13 '19 at 8:55
• Please, make your document example minimal.In it you provide only a package related to your problem. btw, subfigure is obsolete package, replace it with subfig (which has different syntax) or even better with subcaption. from my answer on your previous question you should know that you can remove amsmath˙package sine you use it supersede mathtools, etc – Zarko Aug 13 '19 at 9:02

Here is my comment in your code:

\documentclass[10pt,journal,compsoc]{IEEEtran}
% *** MATH PACKAGES ***
%
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{textcomp}
\usepackage{filecontents}
\usepackage{microtype}
\usepackage{float}
\usepackage{booktabs,makecell,tabularx}
\usepackage{url}
\usepackage{booktabs}
\usepackage{subfigure}
\newcommand{\tvar}[2]{%
\mathrm{#1}_{\mathrm{#2}}%
}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{siunitx}
\usepackage[utf8]{inputenc}
\renewcommand{\thetable}{\arabic{table}}
\usepackage{etoolbox}
\usepackage{xparse}
\makeatletter
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\begin{document}
\begin{algorithm}
\caption{Esdfdfsy}
\label{alg:ALG1}
\begin{flushleft}
\textbf{OUTPUT:} Prediction of $W_{t_c}$ records
\end{flushleft}
\begin{algorithmic}

\ForAll {$i$=1 to $N$}
\Comment{fdasdfn fdas}
\State dfasdsf $afsddfs_i$  from $T_i$
\EndFor

\State Apply $HAT$ to  $\bigcup\limits_{i=1}^{F} W_{i}$ \Comment{IIIIII process -fdsdfsfsd}\\

\If { $wr < htr$ }          \Comment{Nfsddfssdfasdf  }
\State $s = 0$
\Else
\State $s = \floor {wr / htr}$
\EndIf
\State xxx = 0
\While {     $WYU_c \not=$\O }
\State c = c + 1
\State Update $XXXXX$ with $W_{(dfsf2)-f}$

$\parallel$   \Comment{in parallel}
\\$Eadssad (W_{t_{c-1}})$ =  Predict ( dasda ($dasa8_{t_c-2,..,t_c-N-1}$ ) ) over $dsad_{t_c-1}$
$\parallel$
\\ $J48 (W_{t_{c-1}})$ = Predict ($J48_{t_{c-2}}$) over $W_{t_c-1}$     \Comment{This is done as part of the ensemble }

\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}


• Thanks @koleygr, I get an error for your code: Undefined control sequence. \ForAll – Avi Aug 13 '19 at 9:13
• possibly you forgot to add \usepackage{algpseudocode}` ... please be carefull with these three lines and their order as said in the comment too – koleygr Aug 13 '19 at 9:15