You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在LaTeX调用\listofalgorithms时跳过指定算法不列入目录

解决方案

你使用的algorithm2e包的标题逻辑与标准的figure/table环境不同,之前的方案失效就是这个原因,有两种可用的实现方法:

方法1:无需额外加载宏包(推荐)

利用TeX的局部作用域特性,在不需要列入目录的algorithm环境内临时禁用写入目录的命令,该设置只会作用于当前环境,不会影响后续算法,计数器也会正常递增。
修改后的完整示例代码:

\documentclass{article}    
\usepackage[lined,boxed,commentsnumbered, ruled,vlined,linesnumbered, frenchkw]{algorithm2e}    
\begin{document}    

\listofalgorithms

\begin{algorithm}
\caption{我希望这个出现在算法目录中}
执行操作 \;
\end{algorithm}
    
\begin{algorithm}
% 仅在当前环境临时禁用写入目录的命令
\let\addcontentsline\relax
\caption{我不希望这个出现在算法目录中}
执行其他操作\;
\end{algorithm}

\begin{algorithm}
\caption{我希望这个出现在算法目录中,编号保持为3而不是2}
不执行操作 \;
\end{algorithm}

\end{document}

方法2:使用caption宏包适配你之前的captionsetup方案

你之前使用\captionsetup报错是因为没有加载caption宏包,algorithm2e本身不自带该命令支持,加载宏包后即可正常使用:

\documentclass{article}
% 新增加载caption宏包
\usepackage{caption}
\usepackage[lined,boxed,commentsnumbered, ruled,vlined,linesnumbered, frenchkw]{algorithm2e}    
\begin{document}    

\listofalgorithms

\begin{algorithm}
\caption{我希望这个出现在算法目录中}
执行操作 \;
\end{algorithm}
    
\begin{algorithm}
\captionsetup{list=no}
\caption{我不希望这个出现在算法目录中}
执行其他操作\;
\end{algorithm}

\begin{algorithm}
\caption{我希望这个出现在算法目录中,编号保持为3而不是2}
不执行操作 \;
\end{algorithm}

\end{document}

原方案失效原因说明

  • 使用\caption[]{Algorithm}的方式对标准浮动体有效是因为标准实现里可选参数为空就不会写入目录,但algorithm2e的标题逻辑不同,就算可选参数为空也会生成只有点线和页码的空目录条目,无法达到隐藏效果。
  • 直接使用\captionsetup报错是因为该命令由caption宏包提供,未加载宏包时自然无法识别。

内容的提问来源于stack exchange,提问作者user2964288

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 17:09:04