我正在使用包algorithm2e
并使用创建一个算法列表\listofalgorithms
。我的问题是,不仅算法(算法),还有函数(功能) 显示在算法列表中。
该函数(见以下示例)是否可能func()
未显示在算法列表中?
\documentclass{scrreprt}
\usepackage{algorithm}
\usepackage[ruled,algosection,algo2e]{algorithm2e}
\begin{document}
\begin{algorithm}
\caption{Foo bar}
...
\end{algorithm}
\begin{function}
\caption{func()}
...
\end{function}
\newpage
\renewcommand*{\listalgorithmname}{Algorithmenverzeichnis}
\listofalgorithms
\clearpage
\end{document}
答案1
文档第 17 页描述了此行为:
标签现在将过程或函数的名称(标题中括号之前的文本)作为参考(而不是像经典算法环境那样的数字)。
您可以通过重新定义包的一些内部结构来改变它:
\makeatletter
\long\def\algocf@caption@proc#1[#2]#3{%
\ifthenelse{\boolean{algocf@nokwfunc}}{\relax}{%
\SetKwFunction{\algocf@captname#3@}{\algocf@captname#3@}%
}%
% we tell hyperref to use algocfproc as category and to take the appropriate ref.
\ifthenelse{\boolean{algocf@func}}{\def\@proc@func{algocffunc}}{\def\@proc@func{algocfproc}}%
\@ifundefined{hyper@refstepcounter}{\relax}{% if hyper@refstepcounter undefind, no hyperref, else...
\ifthenelse{\boolean{algocf@procnumbered}}{%
\expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%if procnumbered, take \thealgocf as ref
}{%
\expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%else take procedure or function name
}%
\hyper@refstepcounter{\@proc@func}%
}%
\ifthenelse{\boolean{algocf@procnumbered}}{\relax}{%
\addtocounter{algocf}{-1}% \caption do a refstepcounter, so we restore the precedent value
\gdef\@currentlabel{\algocf@captname#3@}% let the label be the name of the function, not the counter
}%
\ifthenelse{\equal{\algocf@captparam#2@}{\arg@e}}{% if no paramater, we remove the ()
\algocf@latexcaption{#1}[\algocf@captname#2@]{#3}%
}{% else we give the complete name
\algocf@latexcaption{#1}[#2]{#3}%
}%
}%
\makeatother
我删除了以下声明:
\algocf@procname\nobreakspace