2

Although everyone considers this worst practice I'm working on merging all lists in my document into one (toc, lot and lof). I got the easiest way to do this from Combine Table of Content, Figures and Tables:

\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}

Which creates something along those lines: table of contents with list of tables and figures included

Although it seems crowded at first glance, I like how it turned out.

My problem is that I want to define a new float environment iEQ using the float package:

\newfloat{iEQ}{H}{toc}

This float environment should also be listed in the table of contents, so I used toc as the extension, but this fails:

test.toc | Something's wrong--perhaps a missing \item.

at this line:

\contentsline {iEQ}{\numberline {1}{\ignorespaces test\relax }}{3}{iEQ.1}%

How do I make the float package's \newfloat environments appear in the table of contents?

1 Answer 1

3

With a KOMA-Script class use \DeclareNewTOC (provided by KOMA-Script package tocbasic) to define a new 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}

or with the prerelease of KOMA-Script version 3.28 (can be installed from the KOMA-Script website):

\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}

Or without \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}

If you really want to use \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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .