我指的是这'如何从 algorithm2e 中的 \listofalgorithms 中排除函数' 问题的答案。答案中提供的解决方案只是省略了算法列表中的单词function
,但仍然打印没有数字的函数名称(数字被替换-
)。
我想从算法列表中完全删除所有函数和过程的条目。这可能吗?
答案1
下面的最小示例使用了以下答案中的代码algorithm2e
:排除函数\listofalgorithms
\renewcommand{\addcontentsline}[3]{}
在算法列表的适当位置添加内容:
\documentclass{scrreprt}
\usepackage{algorithm}
\usepackage[ruled,algosection,algo2e]{algorithm2e}
\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
}%
\renewcommand{\addcontentsline}[3]{}% Remove placement of content
\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
\begin{document}
\begin{function}
\caption{func()}
...
\end{function}
\begin{algorithm}
\caption{Foo bar}
...
\end{algorithm}
\newpage
\renewcommand*{\listalgorithmname}{Algorithmenverzeichnis}
\listofalgorithms
\clearpage
\end{document}