我想要一种方法来将目录、图表和表格合并到同一个列表中。目前我有
\tableofcontents
\renewcommand\listtablename{Case Tables}
\listoftables
\listoffigures
例如:
1 Section
2. Subsection
Figure
Figure
2. Section
1. Subsection
Table
Table
2. Subsection
Figure
答案1
一种可能的解决方案是强制 LaTeX 不再写入.lof
和.lot
文件,而是将两个文件的文件句柄更改为.toc
文件。
这是通过
\immediate\write\@auxout{%
\string\let\string\tf@lot\string\tf@toc^^J%
\string\let\string\tf@lof\string\tf@toc
}
就在文档的开头。
\documentclass{article}
\usepackage{blindtext}
\usepackage{pgffor}
\usepackage{xpatch}
\usepackage{tocloft}
\usepackage{caption}
\makeatletter
\AtBeginDocument{
\addtolength{\cftfignumwidth}{25pt}
\addtolength{\cfttabnumwidth}{25pt}
% Add the prefixes
\renewcommand{\p@table}{Table}
\renewcommand{\p@figure}{Figure}
% Change the file handle from lot to toc and from lof to toc
\immediate\write\@auxout{%
\string\let\string\tf@lot\string\tf@toc^^J%
\string\let\string\tf@lof\string\tf@toc
}
}
\makeatother
\captionsetup[figure]{listformat=simple}
\captionsetup[table]{listformat=simple}
\begin{document}
\tableofcontents
\cleardoublepage
\foreach \x in {1,...,5} {%
\section{Foo section \x}
\blindtext
\subsection{Foo subsection 1}
\blindtext
\begin{figure}[htp]
\caption{A foo figure with number \x }
\end{figure}
\subsubsection{Foo subsubsection 2}
\begin{table}[htp]
\caption{A foo table with number \x }
\end{table}
}
\end{document}