![algorithm2e - 未定义控制序列。\end](https://linux22.com/image/355982/algorithm2e%20-%20%E6%9C%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E5%88%B6%E5%BA%8F%E5%88%97%E3%80%82%5Cend.png)
我不明白为什么我在“\end{algorithm}”行出现此错误
\usepackage[spanish]{babel}
\selectlanguage{spanish}
\usepackage[spanish,onelanguage,linesnumbered]{algorithm2e} %for psuedo code
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\begin{algorithm}[H] %or another one check
\DontPrintSemicolon
\SetKwFunction{FSonIguales}{son\_iguales}
\SetKwProg{Fn}{Funcion}{}{fin}
\Fn{\FSonIguales{$X[1..n]$, $Y[1..n]$}}{
\;\comment{\# Si es array vacío, devuelvo verdadero}\;
\uIf{$X.longitud == 0$ $\&\&$ $Y.longitud == 0$}{
\KwRet verdadero\;
}
\;\comment{\# Compruebo si primeros elemento son distintos}\;
\uElseIf{$X[1]$ $!=$ $Y[1]$}{
\KwRet falso\;
}
\;\comment{\# Compruebo el resto del array}\;
\Else{
\KwRet son\_iguales($X[2..n]$, $Y[2..n]$)\;
}
}
\end{algorithm}
Line 126 - Undefined control sequence. \end
Line 126 - Undefined control sequence. \end
Line 126 - Undefined control sequence. \end
答案1
未定义的控制序列是\comment
。以下是完整的错误消息:
! Undefined control sequence.
<argument> \;\comment
{\# Si es array vacío, devuelvo verdadero}\; \uIf {$...
l.25 \end
{algorithm}
?
你能做什么?不要使用\comment
,因为它是未定义的。注释的宏是\tcp
和\tcc
,在手册的第 10.3 节中有描述algorithm2e
。