![扫描使用 \algocf@Fnmain \input{..} 时文件结束](https://linux22.com/image/338132/%E6%89%AB%E6%8F%8F%E4%BD%BF%E7%94%A8%20%5Calgocf%40Fnmain%20%5Cinput%7B..%7D%20%E6%97%B6%E6%96%87%E4%BB%B6%E7%BB%93%E6%9D%9F.png)
当我编译使用 algorithm2e 包编写的以下伪代码时,我收到编译错误,并显示一条无用的错误消息。这是我的错误消息
“扫描 \algocf@Fnmain \input{chapters/4_lan} 的使用时文件结束”
\usepackage[vlined,ruled]{algorithm2e}
%% optional fonts and color configuration
\SetAlFnt{\sffamily}
\renewcommand\ArgSty{\normalfont\ttfamily}
\renewcommand\KwSty[1]{\textnormal{\textbf{\ttfamily#1}}\unskip}
\SetAlCapFnt{\normalfont\ttfamily\large}
\renewcommand\AlCapNameFnt{\ttfamily\large}
% vertical rules in cyan color
\makeatletter
\renewcommand{\algocf@Vline}[1]{% no vskip in between boxes but a strut to separate them,
\strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
\algocf@push{\skiprule}% move to the right before the vertical rule
\hbox{\bgroup\color{cyan}\vrule\egroup%
\vtop{\algocf@push{\skiptext}%move the right after the rule
\vtop{\algocf@addskiptotal #1}\bgroup\color{cyan}\Hlne\egroup}}\vskip\skiphlne% inside the block
\algocf@pop{\skiprule}%\algocf@subskiptotal% restore indentation
\nointerlineskip}% no vskip after
%
\renewcommand{\algocf@Vsline}[1]{% no vskip in between boxes but a strut to separate them,
\strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
\algocf@bblockcode%
\algocf@push{\skiprule}% move to the right before the vertical rule
\hbox{\bgroup\color{cyan}\vrule\egroup% the vertical rule
\vtop{\algocf@push{\skiptext}%move the right after the rule
\vtop{\algocf@addskiptotal #1}}}% inside the block
\algocf@pop{\skiprule}% restore indentation
\algocf@eblockcode%
}
%
\makeatother
\SetKwProg{Fn}{Function}{}{}
\begin{algorithm}
\Fn{trackAndFilter (past, pointCloud)}{
past $\leftarrow$ structure of vectors of centroids in past $n$ frames\;
$n$ $\larrow$ size of past\;
centroid $\in \big[x, y, z, match \big]$\;
\For{$i$ from 1 to $n$ }{
\For{$centroid1$ from past\big[i\big].begin to past\big[i\big].end}{
\For{$centroid2$ from past[i-1].begin to past\big[i-1\big].end}{
\If{distance between centroid1 and centroid2 $>$ 50cm}{
$centroid1[match]$ $+=$ 1\;}
}
\If{$i>1$ AND $centroid1[match]$ $==$ 0}{
\For{$j$ from i to 1}{
\For{$centroid3$ from past\big[i-2\big].begin to past\big[i-1\big].end}{
\If{distance between centroid1 and centroid2 $>$ 50cm}{
$centroid1\big[match\big]$ $+=$ 1\;}
}
\If{$centroid1\big[match\big]$ $>$ 0}{
break\;}
}
}
}
\For{$centroid4$ from past[$n-1$].begin to past\big[$n-1$\big].end}{
\If{$centroid4\big[match\big]$ $>$ 2}{
pointCloud $\larrow$ $centroid4$\;
}
}
past $\larrow$ pop out first vector\;
}
\caption{Polling}
\end{algorithm}
我做错了什么?我确保将所有数学运算置于数学模式并转义特殊字符。
答案1
您的开头缺少一个结束括号\Fn
:
\documentclass{article}
\usepackage{xcolor}
\usepackage[vlined,ruled]{algorithm2e}
%% optional fonts and color configuration
\SetAlFnt{\sffamily}
\renewcommand\ArgSty{\normalfont\ttfamily}
\renewcommand\KwSty[1]{\textnormal{\textbf{\ttfamily#1}}\unskip}
\SetAlCapFnt{\normalfont\ttfamily\large}
\renewcommand\AlCapNameFnt{\ttfamily\large}
% vertical rules in cyan color
\makeatletter
\renewcommand{\algocf@Vline}[1]{% no vskip in between boxes but a strut to separate them,
\strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
\algocf@push{\skiprule}% move to the right before the vertical rule
\hbox{\bgroup\color{cyan}\vrule\egroup%
\vtop{\algocf@push{\skiptext}%move the right after the rule
\vtop{\algocf@addskiptotal #1}\bgroup\color{cyan}\Hlne\egroup}}\vskip\skiphlne% inside the block
\algocf@pop{\skiprule}%\algocf@subskiptotal% restore indentation
\nointerlineskip}% no vskip after
%
\renewcommand{\algocf@Vsline}[1]{% no vskip in between boxes but a strut to separate them,
\strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
\algocf@bblockcode%
\algocf@push{\skiprule}% move to the right before the vertical rule
\hbox{\bgroup\color{cyan}\vrule\egroup% the vertical rule
\vtop{\algocf@push{\skiptext}%move the right after the rule
\vtop{\algocf@addskiptotal #1}}}% inside the block
\algocf@pop{\skiprule}% restore indentation
\algocf@eblockcode%
}
%
\makeatother
\SetKwProg{Fn}{Function}{}{}
\newcommand{\larrow}{\leftarrow}
\begin{document}
\begin{algorithm}
\Fn{trackAndFilter (past, pointCloud)}{
past $\leftarrow$ structure of vectors of centroids in past $n$ frames\;
$n$ $\larrow$ size of past\;
centroid $\in \big[x, y, z, match \big]$\;
\For{$i$ from 1 to $n$ }{
\For{$centroid1$ from past\big[i\big].begin to past\big[i\big].end}{
\For{$centroid2$ from past[i-1].begin to past\big[i-1\big].end}{
\If{distance between centroid1 and centroid2 $>$ 50cm}{
$centroid1[match]$ $+=$ 1\;}
}
\If{$i>1$ AND $centroid1[match]$ $==$ 0}{
\For{$j$ from i to 1}{
\For{$centroid3$ from past\big[i-2\big].begin to past\big[i-1\big].end}{
\If{distance between centroid1 and centroid2 $>$ 50cm}{
$centroid1\big[match\big]$ $+=$ 1\;}
}
\If{$centroid1\big[match\big]$ $>$ 0}{
break\;}
}
}
}
\For{$centroid4$ from past[$n-1$].begin to past\big[$n-1$\big].end}{
\If{$centroid4\big[match\big]$ $>$ 2}{
pointCloud $\larrow$ $centroid4$\;
}
}
past $\larrow$ pop out first vector\;
}
}% <--- ...this was missing...
\caption{Polling}
\end{algorithm}
\end{document}