我一直在与 tocloft 斗争,希望它能在所有列表中应用一些自定义功能,但似乎这些功能只对默认列表有效,例如“tocs”、“lofs”和“lots”。对于我定义的列表或像算法那样具有自己的“loa”的列表,它不起作用:
\documentclass{book}
\usepackage{tocloft}
\usepackage{algorithm2e}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\definecolor{red}{RGB}{180,40,50}
\makeatletter
\begingroup
\let\newcounter\@gobble
\let\setcounter\@gobbletwo
\globaldefs\@ne
\let\c@loadepth\@ne
\newlistof{algorithmt}{loa}{\listalgorithmcfname}
\endgroup
\let\l@algorithm\l@algorithms
\makeatother
\renewcommand\cftdotsep{0}
\renewcommand\cftdot{\color{red}\_}
\renewcommand\cftalgorithmtdotsep{0}
\renewcommand\cftalgorithmtleader{\color{red}\_}
\begin{document}
\tableofcontents
\listofalgorithms
\addcontentsline{toc}{chapter}{List of Algorithms}
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}
\chapter{chapter one}
\section{section one}
\begin{table}
\centering A
\caption{test table}
\end{table}
\begin{algorithm}
\centering A
\caption{test algorithm}
\end{algorithm}
\chapter{chapter two}
\section{section one}
\begin{table}
\centering A
\caption{another test table}
\end{table}
\begin{algorithm}
\centering A
\caption{another test algorithm}
\end{algorithm}
\end{document}
答案1
如果你查看该.loa
文件,你会看到
\addvspace {10\p@ }
\addvspace {10\p@ }
\contentsline {algocf}{\numberline {1}{\ignorespaces test algorithm}}{5}
\addvspace {10\p@ }
\contentsline {algocf}{\numberline {2}{\ignorespaces another test algorithm}}{7}
所以,\let\l@algorithm\l@algorithms
你不必说
\let\l@algocf\l@algorithmt
还必须进行一些其他调整。以下是完整的示例。
\documentclass{book}
\usepackage{tocloft}
\usepackage{algorithm2e}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\definecolor{red}{RGB}{180,40,50}
\makeatletter
\begingroup
\let\newcounter\@gobble
\let\setcounter\@gobbletwo
\globaldefs\@ne
\let\c@loadepth\@ne
\newlistof{algorithmt}{loa}{\listalgorithmcfname}
\endgroup
\let\l@algocf\l@algorithmt
\makeatother
\renewcommand\cftdotsep{0}
\renewcommand\cftdot{\color{red}\_}
\renewcommand\cftalgorithmtdotsep{0}
\let\cftalgorithmtleader\cftsecleader
\begin{document}
\tableofcontents
\listofalgorithms
\addcontentsline{toc}{chapter}{List of Algorithms}
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}
\chapter{chapter one}
\section{section one}
\begin{table}
\centering A
\caption{test table}
\end{table}
\begin{algorithm}
\centering A
\caption{test algorithm}
\end{algorithm}
\chapter{chapter two}
\section{section one}
\begin{table}
\centering A
\caption{another test table}
\end{table}
\begin{algorithm}
\centering A
\caption{another test algorithm}
\end{algorithm}
\end{document}
您可能还想将缩进设置为适当的值。