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

LaTeX模板中算法列表与附录列表内容混排问题求助

问题根源

algorithm 包的\listofalgorithms默认使用.loa作为存储列表项的辅助文件,而你通过tocloft定义附录列表时,也指定了同一个.loa文件作为存储载体,导致两个列表的内容互相写入同一文件,最终出现互相混入的情况。

解决方案

将附录列表的辅助文件改为不与algorithm冲突的名称(比如loax),具体修改如下:

  • 修改\newlistof命令的第二个参数,替换原有的loa:
\newlistof[chapter]{anexos}{loax}{\listanexosname}
  • 同步修改\anexos命令里\addcontentsline的第一个参数:
\addcontentsline{loax}{anexos}{\protect\numberline{\Alph{anexos}}#1}\par
修改后的完整代码
\documentclass[letter,12pt,english]{report}   
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage{subfigure}
\usepackage{algorithm, algpseudocode}
\usepackage[subfigure]{tocloft}
\newcommand{\listanexosname}{\hfill\normalfont\normalsize\bfseries List of Appendices}
\newlistof[chapter]{anexos}{loax}{\listanexosname}
\newcommand{\anexos}[1]{%
\refstepcounter{anexos}
\par\noindent\textbf{Appendix \Alph{anexos}. #1}
\addcontentsline{loax}{anexos}{\protect\numberline{\Alph{anexos}}#1}\par
}
\begin{document} 
\title{My work}
\listofalgorithms
\listofanexos

\chapter{Test}
This is a test

\begin{algorithm}[!b]
\caption{My algorithm}\label{alg:binaryPCA}
\begin{algorithmic}[1]
    \State $\Sigma_1 = m$
\end{algorithmic}
\end{algorithm}

\newpage
%\nnchapter{Appendices}
\anexos{My appendix}\label{anexoA} 
This is a test
\section*{Test section}
Some text here

\end{document}
注意事项

修改完成后,务必删除之前编译生成的.loa、.loax、.aux等辅助文件,再连续编译三次LaTeX文档,确保列表内容正确生成。

内容的提问来源于stack exchange,提问作者Jonathan Arley Monsalve Salaza

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 02:29:54