尽管每个人都认为这是最糟糕的做法,但我正在努力将文档中的所有列表合并为一个(toc、lot 和 lof)。我从中找到了最简单的方法合并目录、图表和表格:
\documentclass{scrbook}
\usepackage{caption, float, hyperref}
\makeatletter
\AtBeginDocument{
\immediate\write\@auxout{
\string\let\string\tf@lof\string\tf@toc
% ...
}}
\makeatother
\begin{document}
\tableofcontents
\chapter{One}
\begin{figure}[H]
figure \caption{Foo figure}\label{fig:foo}
\end{figure}
\end{document}
虽然乍一看似乎很拥挤,但我很喜欢。
我的问题是我想定义一个新的浮动环境 iEQ
使用 float
包裹:
\newfloat{iEQ}{H}{toc}
这个浮动环境也应该列在目录中,所以我用它toc
作为扩展,但是失败了:
test.toc | Something's wrong--perhaps a missing \item.
在这一行:
\contentsline {iEQ}{\numberline {1}{\ignorespaces test\relax }}{3}{iEQ.1}%
我如何制作 float
包裹的 \newfloat
环境是否出现在目录中?
答案1
使用 KOMA-Script 类\DeclareNewTOC
(由 KOMA-Script 包提供tocbasic
)定义新的 TOC:
\documentclass{scrbook}
\usepackage{float}% only used for the H-position
\usepackage{scrhack}% because of package float together a KOMA-Script class
\usepackage{hyperref}
\DeclareNewTOC[
counterwithin=chapter,
float,
floattype=4,
floatpos=H
]{iEQ}
\makeatletter
\renewcommand*{\l@iEQ}{\l@figure}
\renewcommand*{\ext@iEQ}{toc}
\renewcommand*{\ext@figure}{toc}
\makeatother
\begin{document}
\tableofcontents\KOMAScriptVersion
\chapter{One}
\begin{figure}[H]
figure \caption{Foo figure}\label{fig:foo}
\end{figure}
\begin{iEQ}
iEQ \caption{Bar iEQ}\label{iEQ:bar}
\end{iEQ}
\end{document}
或者使用 KOMA-Script 3.28 版的预发布版本(可以从KOMA-Script 网站):
\documentclass{scrbook}[2019/12/06]
\usepackage{float}% only used for the H-position
\usepackage{scrhack}% because of package float together a KOMA-Script class
\usepackage{hyperref}
\DeclareNewTOC[
counterwithin=chapter,
float,
floattype=4,
floatpos=H,
tocentrylevel:=figure,
tocentryindent:=figure,
tocentrynumwidth:=figure
]{iEQ}
\makeatletter
\renewcommand*{\ext@iEQ}{toc}
\renewcommand*{\ext@figure}{toc}
\makeatother
\begin{document}
\tableofcontents\KOMAScriptVersion
\chapter{One}
\begin{figure}[H]
figure \caption{Foo figure}\label{fig:foo}
\end{figure}
\begin{iEQ}
iEQ \caption{Bar iEQ}\label{iEQ:bar}
\end{iEQ}
\end{document}
或者没有\DeclareNewTOC
:
\documentclass{scrbook}
\usepackage{float}% only used for the H-position
\usepackage{scrhack}% because of package float together a KOMA-Script class
\usepackage{hyperref}
\makeatletter
\newenvironment{iEQ}%
{\@float{iEQ}}
{\end@float}
\newcommand*{\fps@iEQ}{H}
\newcommand*{\ftype@iEQ}{4}
\newcounter{iEQ}
\counterwithin{iEQ}{chapter}
\newcommand*{\iEQformat}{IEQ~\theiEQ\autodot}
\newcommand*{\l@iEQ}{\l@figure}
\newcommand*{\ext@iEQ}{toc}
\renewcommand*{\ext@figure}{toc}
\makeatother
\begin{document}
\tableofcontents%\KOMAScriptVersion
\chapter{One}
\begin{figure}[H]
figure \caption{Foo figure}\label{fig:foo}
\end{figure}
\begin{iEQ}
iEQ \caption{Bar iEQ}\label{iEQ:bar}
\end{iEQ}
\end{document}
如果你确实想使用\newfloat
:
\documentclass{scrbook}
\usepackage{scrhack}% because of package float together a KOMA-Script class
\usepackage{caption, float, hyperref}
\newfloat{iEQ}{H}{iEQ}[chapter]
\makeatletter
\AtBeginDocument{
\immediate\write\@auxout{
\string\let\string\tf@lof\string\tf@toc
\string\let\string\tf@iEQ\string\tf@toc
% ...
}}
\newcommand{\l@iEQ}{\l@figure}
\makeatother
\begin{document}
\tableofcontents
\listof{iEQ}{Test}
\chapter{One}
\begin{figure}[H]
figure \caption{Foo figure}\label{fig:foo}
\end{figure}
\begin{iEQ}
iEQ \caption{Bar iEQ}\label{iEQ:bar}
\end{iEQ}
\end{document}