Latex 中格式错误的算法

Latex 中格式错误的算法

在此处输入图片描述

我正在写一篇论文乳胶我还包括算法。我添加了每个算法的包,例如

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

我写if else在了里面for loop,并且那个循环写在了程序但它来错了。

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

答案1

问题出在我必须选择的序言包组合上:

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

上面的代码给出:

在此处输入图片描述

相关内容