1

I have used tocbasic to create a custom environment. The appearance of this environment's listing, however, differs from the default listings (i.e., \listoffigures and \listoftables).

Differences in horizontal formatting (indentation, width) can be fixed using the tocentryindent and tocentrynumwidth settings. However, differences in vertical spacing continue to be a problem (both between items and between the heading and the first item).

Does \DeclareNewToc accept options that allow replication of the vertical spacing of the default listings? I failed to identify suitable options in the KOMA-script manual's Table 15.1 (TOC-entry style attributes).

MWE:

\documentclass{report}
\usepackage{tocbasic}
\usepackage{tocbibind}

\DeclareTOCStyleEntries{tocline}{figure,table}
\DeclareNewTOC[%
    type=thing,
    float,
    name=Thing,
    listname={List of Things},
    counterwithin=chapter,
    tocentryindent:=figure,
    tocentrynumwidth:=figure
]{lop}



\begin{document}
    % no page breaks (tex.stackexchange.com/a/30750)
    \begingroup
        \let\cleardoublepage\relax
        \let\clearpage\relax
        \listoffigures
        \listoftables
        \listofthings
    \endgroup

    \chapter{First}
    \begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 1} \end{figure}
    \begin{table}[ht]  \centering\fbox{Table} \caption{Table 1}  \end{table}
    \begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 1}  \end{thing}

    \chapter{Second}
    \begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 2} \end{figure}
    \begin{table}[ht]  \centering\fbox{Table} \caption{Table 2}  \end{table}
    \begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 2}  \end{thing}
\end{document}

enter image description here


Edit: The following image, using the xpatch example from the answer, splices the three lists, which shows different vertical spacing between the heading and the first element.

enter image description here

1 Answer 1

1

If package tocbasic should controll the output of the list headings and the space after the heading, use

\renewcommand{\listoffigures}{\listoftoc[\listfigurename]{lof}}
\renewcommand{\listoftables}{\listoftoc[\listtablename]{lot}}

Each \chapter adds 10pt vertical space to LoF and the LoT. To do the same for the new defined list, you have to patch \@chapter:

\makeatletter
\AddToHook{cmd/@chapter/after}{\addtocontents{lop}{\protect\addvspace{10\p@}}}
\makeatother

Example:

\documentclass{report}
\usepackage{tocbibind}% load before tocbasic
\usepackage{tocbasic}

\renewcommand{\listoffigures}{\listoftoc[\listfigurename]{lof}}
\renewcommand{\listoftables}{\listoftoc[\listtablename]{lot}}

\DeclareTOCStyleEntries{tocline}{figure,table}
\DeclareNewTOC[%
    type=thing,
    float,
    name=Thing,
    listname={List of Things},
    counterwithin=chapter,
    tocentryindent:=figure,
    tocentrynumwidth:=figure
]{lop}

\makeatletter
\AddToHook{cmd/@chapter/after}{\addtocontents{lop}{\protect\addvspace{10\p@}}}
\makeatother

\begin{document}
% no page breaks (tex.stackexchange.com/a/30750)
\begingroup
    \let\cleardoublepage\relax
    \let\clearpage\relax
    \listoffigures
    \listoftables
    \listofthings
\endgroup

\chapter{First}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 1} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 1}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 1}  \end{thing}

\chapter{Second}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 2} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 2}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 2}  \end{thing}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 3} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 3}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 3}  \end{thing}
\end{document}

enter image description here

Or you could use

\usepackage{xpatch}
\makeatletter
\xapptocmd{\@chapter}
  {\addtocontents{lop}{\protect\addvspace{10\p@}}}
  {}{\PatchFailed}
\makeatother

Example:

\documentclass{report}
\usepackage{tocbibind}% load before tocbasic
\usepackage{tocbasic}

\renewcommand{\listoffigures}{\listoftoc[\listfigurename]{lof}}
\renewcommand{\listoftables}{\listoftoc[\listtablename]{lot}}

\DeclareTOCStyleEntries{tocline}{figure,table}
\DeclareNewTOC[%
    type=thing,
    float,
    name=Thing,
    listname={List of Things},
    counterwithin=chapter,
    tocentryindent:=figure,
    tocentrynumwidth:=figure
]{lop}

\usepackage{xpatch}
\makeatletter
\xapptocmd{\@chapter}
  {\addtocontents{lop}{\protect\addvspace{10\p@}}}
  {}{\PatchFailed}
\makeatother

\begin{document}
% no page breaks (tex.stackexchange.com/a/30750)
\begingroup
    \let\cleardoublepage\relax
    \let\clearpage\relax
    \listoffigures
    \listoftables
    \listofthings
\endgroup

\chapter{First}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 1} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 1}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 1}  \end{thing}

\chapter{Second}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 2} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 2}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 2}  \end{thing}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 3} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 3}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 3}  \end{thing}
\end{document}

The result is the same as above.


It would be easier if you can switch to a KOMA-Script class (loads tocbasic automatically):

\documentclass[
  listof=totoc,
  index=totoc,
  bibliography=totoc,
  sfdefaults=false,% needs version 3.39 or newer
  listof=leveldown
]{scrreprt}

\setuptoc{toc}{totoc}% if there should really be an entry for ToC in ToC

\DeclareNewTOC[%
    type=thing,
    float,
    name=Thing,
    listname={List of Things},
    counterwithin=chapter,
    tocentryindent:=figure,
    tocentrynumwidth:=figure
]{lop}

\begin{document}
\tableofcontents

\addchap{Lists}
\listoffigures
\listoftables
\listofthings

\chapter{First}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 1} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 1}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 1}  \end{thing}

\chapter{Second}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 2} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 2}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 2}  \end{thing}
\begin{figure}[ht] \centering\fbox{Figure}\caption{Figure 3} \end{figure}
\begin{table}[ht]  \centering\fbox{Table} \caption{Table 3}  \end{table}
\begin{thing}[ht]  \centering\fbox{Thing} \caption{Thing 3}  \end{thing}
\end{document}

enter image description here

9
  • Curiously I am unable to reproduce your output (I am using pdflatex). The vertical spacing is still off for 'List of Things'. Using pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021).
    – user001
    Nov 24, 2021 at 21:30
  • You have to run twice.
    – esdd
    Nov 24, 2021 at 21:31
  • Yes, even so (pdflatex "$f.tex" && pdflatex "$f.tex"). The console output appears benign.
    – user001
    Nov 24, 2021 at 21:33
  • Did you use my MWE?
    – esdd
    Nov 24, 2021 at 21:41
  • Yes, thank you. I can reproduce your output with the second MWE (the one with scrreprt). Odd that the output using plain report is not reproducible. Unfortunately, I don't think I can use scrreprt in my actual document because I must use a custom sty file, and I wind up getting various compilation errors (e.g., 'Class scrreprt Error: undefined old font command `\rm'.').
    – user001
    Nov 24, 2021 at 21:44

You must log in to answer this question.

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