! 未定义的控制序列。\精灵

! 未定义的控制序列。\精灵

\eIf{$list size > 0$} 我在位置输入此 if 语句后尝试打开 if 语句\elf{$stopAfterNext$ is not empty},但出现以下错误。只要从中删除斜线,我就可以编译文档 elf{$stopAfterNext$ is not empty}。我该如何修复它?

错误:

! Undefined control sequence.
<recently read> \elf
l.26 }

代码:

\documentclass{article}
%\usepackage{algorithmic}% http://ctan.org/pkg/algorithms
\usepackage[]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{latitude, longitude, mac, route, direction}
%\KwResult{how to write algorithm with \LaTeX2e }
 initialize $list$ as an empty  list of integers. \\
%\While{not at end of this document}{
%read current\;
$list$ = Get stop Order from behaviour; \\
\eIf{$list size > 0$}{
  find the last stop name in the behaviour table of this mac;\\
   find the $stop\_id$ of the current location; \\
  find all possible avialable next stops of this
                 $stop\_id$; \\

      calculate the distance to all after next;\\   
  insert the result into after next;    \\  
  String $stopAfterNext$ = check  $stop\_name$ with $stop\_distance < 150$ in after next table; \\
  \elf{$stopAfterNext$ is not empty}{ \\
  String $stopBetween$ = find the name in the stops table;\\

  }          
}{
  find the closet stop of the producer current location; \\
  insert it into next table; \\
  find initializer; \\
  \eIf{initializer is available}{
     get the initializer stop name;  \\
     restore all stop name for this mac to the behaviour table;

  }

}
\caption{Detection algorithm.}
\end{algorithm}

\end{document}

答案1

我不太确定这是否是您期望的输出,但编译时没有错误:

在此处输入图片描述

\documentclass{article}
\usepackage[]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{latitude, longitude, mac, route, direction}
%\KwResult{how to write algorithm with \LaTeX2e }
 initialize $list$ as an empty  list of integers. \\
%\While{not at end of this document}{
%read current\;
$list$ = Get stop Order from behaviour; \\
\eIf{$list size > 0$}{
  find the last stop name in the behaviour table of this mac;\\
   find the $stop\_id$ of the current location; \\
  find all possible avialable next stops of this
                 $stop\_id$;                  
      calculate the distance to all after next;\\   
  insert the result into after next;    \\  
  String $stopAfterNext$ = check  $stop\_name$ with $stop\_distance < 150$ in after next table; \\
  \eIf{$stopAfterNext$ is not empty}{%\\
  String $stopBetween$ = find the name in the stops table;
  }

}{%
  find the closet stop of the producer current location; \\
  insert it into next table; \\
  find initializer; \\
  \eIf{initializer is available}{
     get the initializer stop name;  \\
     restore all stop name for this mac to the behaviour table;
  }

}
\caption{Detection algorithm.}
\end{algorithm}

\end{document}

相关内容