2

enter image description here

I am writing a paper in latex and there I am including algorithm. I added every package of an algorithm like

  • \usepackage{program}
  • \usepackage{algorithm}
  • \usepackage{algpseudocode}
  • \usepackage{algorithmic}
  • \usepackage[options ]{algorithm2e}

I wrote if else with in for loop and that loop is written inside the body of procedure but its wrongly come.

\begin{algorithm}[H]
\caption{Euclid’s algorithm}
\label{alg:euclid}

\begin{algorithmic}[1]
\State $U$: a set of authentic users
\State $T$: a set containing trustor and trustee information
    \Procedure{DepthDetection}{$T_{t_h}$, $U_i$}
    \State $T_{u_i} \gets$ list of trustee taking $U_i$ as trustor
    \State $I_{u_i} \gets$ list of items rated by $U_i$
    \State Build $U_i$'s trust network using $T_{t_h}$
    \For{each item $i$ in $I_{u_i}$}
    \State $NU_{u_i} \gets$ list of users who rated $I_i$
        \For{each user $u$ in $NU_{u_i}$ }
            \If{$u$ is in $T_{u_i}$}
                \State use the rating and trust of $u$ for prediction of rating
            \EndIf
        \EndFor
    \EndFor
    \State \textbf{return} $L$
    \EndProcedure
\end{algorithmic}
\end{algorithm}
koleygr
  • 20,105
  • Welcome to TeX.SE! I managed to get the output of your photo, by loading some wrong combinations of packages. The correct packages used in my answer. When I got your output there was many latex errors in the code... Possibly you had the same. Even if the case is this, please upload the full code used for the output and just add that you get some errors (or the first error you get there) – koleygr Sep 17 '18 at 05:01
  • Please next time post a complete document so that people can reproduce the problem and debug. Also if you get an error ask about the error message, the pdf output after an error is not intended to be used. – David Carlisle Sep 17 '18 at 06:39

1 Answers1

1

The problem was in the preamble packages combination I had to chose:

\documentclass{article}

    \usepackage{program}
    \usepackage{algorithm}
    \usepackage{algpseudocode}
    %\usepackage{algorithmicx}
    %\usepackage{algorithm2e}

\begin{document}
\begin{algorithm}[H]
\caption{Euclid’s algorithm}
\label{alg:euclid}

\begin{algorithmic}[1]
\State $U$: a set of authentic users
\State $T$: a set containing trustor and trustee information
    \Procedure{DepthDetection}{$T_{t_h}$, $U_i$}
    \State $T_{u_i} \gets$ list of trustee taking $U_i$ as trustor
    \State $I_{u_i} \gets$ list of items rated by $U_i$
    \State Build $U_i$'s trust network using $T_{t_h}$
    \For{each item $i$ in $I_{u_i}$}
    \State $NU_{u_i} \gets$ list of users who rated $I_i$
        \For{each user $u$ in $NU_{u_i}$ }
            \If{$u$ is in $T_{u_i}$}
                \State use the rating and trust of $u$ for prediction of rating
            \EndIf
        \EndFor
    \EndFor
    \State \textbf{return} $L$
    \EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

The above code gives:

enter image description here

koleygr
  • 20,105