嵌套 if 在我的 latex 算法代码中不起作用

嵌套 if 在我的 latex 算法代码中不起作用

我试图在 Latex 上编写嵌套的 if 伪代码,但出现以下错误:

LaTeX 错误:命令 \NOT 尚未定义。

\begin{algorithm}[!htbp]
\begin{algorithmic}
\STATE \textbf{Step 5}: Compare each sentence Scores and CFs to determine the class it belong to:
\begin{ALC@g}
\IF {(FR\_Score[sentence] $>$ NFR\_Score[sentence])} 
\STATE Class[Sentence] = FR  
\ELSIF{(FR\_Score[sentence] $<$ NFR\_Score[sentence]) }
\STATE Class [Sentence] = NFR 
\ELSIF {(FR\_Score[sentence] == NFR\_Score[sentence])} 
\begin{ALC@g}
\IF{(FR\_CF[sentence] $>$ NFR\_CF[sentence])} 

\STATE Class[Sentence] = FR  

\ELSIF {(FR\_CF[sentence] $<$ NFR\_CF[sentence])} 

\STATE Class[Sentence] = NFR  

\ELSIF {(FR\_CF[sentence]  == NFR\_CF[sentence])} 

\STATE Class [Sentence] = Nan
\end{ALC@g}
\end{ALC@g}
\end{algorithmic}
\end{algorithm}

从代码中删除 \begin{ALC@g} ..\end{ALC@g} 并添加 \ENDIF 后更新,问题得到解决,但算法末尾出现 0= 符号 在此处输入图片描述

答案1

我想知道您在哪里找到\begin{ALC@g}\end{ALC@g}记录的。您想\IF用 来结束语句\ENDIF

\documentclass{article}
\usepackage{algorithm,algorithmic}

\begin{document}

\begin{algorithm}[!htbp]
\begin{algorithmic}
\STATE \textbf{Step 5}: Compare each sentence Scores and CFs to determine the class it belong to:
\IF {(FR\_Score[sentence] $>$ NFR\_Score[sentence])} 
  \STATE Class[Sentence] = FR  
\ELSIF{(FR\_Score[sentence] $<$ NFR\_Score[sentence]) }
  \STATE Class [Sentence] = NFR 
\ELSIF {(FR\_Score[sentence] == NFR\_Score[sentence])} 
  \IF{(FR\_CF[sentence] $>$ NFR\_CF[sentence])} 
    \STATE Class[Sentence] = FR  
  \ELSIF {(FR\_CF[sentence] $<$ NFR\_CF[sentence])} 
    \STATE Class[Sentence] = NFR  
  \ELSIF {(FR\_CF[sentence]  == NFR\_CF[sentence])} 
    \STATE Class [Sentence] = Nan
  \ENDIF
\ENDIF
\end{algorithmic}
\end{algorithm}

\end{document}

在此处输入图片描述

相关内容