[Tex/LaTex] How to add a single line vertical space to list of figures

floatskoma-scriptscrbooktable of contentsvertical alignment

I have a document of scrbook class, which defines \chapters, \sections, and so on. I use a lot of figures. What's special about my document is that the Chapters are numbered 1, 2, 3, …; the sections are numbered 1.1, 1.2, 1.3, …; but my Appendix is a \chapter* without number, and the sections of the the Appendix are numbered with \Alph{section}.

Now, my problem is that the \listoffigures always produces a vertical space (empty line) between figures of different chapters, but it does not handle the appendix sections as chapters. While figures 4.1, 4.2, 4.3 are grouped together, and also 5.1, 5.2, I have the issue that all figures from all appendices (A, B, C, D) are grouped together without any vertical space.

This is a very specific issue, let me try to create a minimal working example:

\documentclass{scrbook}
\begin{document}
\listoffigures
\chapter{Lorem}
\begin{figure}[htb]
  \caption{1st lorum figure.}
\end{figure}
\begin{figure}[htb]
  \caption{2nd lorum figure.}
\end{figure}
\chapter{Ipsun}
\begin{figure}[htb]
  \caption{1st ipsum figure.}
\end{figure}
\begin{figure}[htb]
  \caption{2nd ipsum figure.}
\end{figure}
\chapter{Dolorem}
\appendix
\chapter*{Appendix}
  \renewcommand{\thesection}{\Alph{section}}
  \renewcommand{\thefigure}{\thesection.\arabic{figure}}
  \section{Lorem (Supplemental)}
    \begin{figure}[htb]
      \caption{3rd lorum figure.}
    \end{figure}
    \begin{figure}[htb]
      \caption{4th lorum figure.}
    \end{figure}
  \section{Ipsum (Supplemental)}
    \begin{figure}[htb]
      \caption{3rd ipsum figure.}
    \end{figure}
    \begin{figure}[htb]
      \caption{4th ipsum figure.}
    \end{figure}
  \section{Dolorem (Supplemental)}
\end{document}

This screenshot of the MWE visualizes my problem best:

screenshot

How to add a single line vertical space to list of figures between the appendix sections only?

Best Answer

This is slightly tricky. As sections do not start on new pages and so do not clear the list of figures one can not hook in to the section change commands to write extra vertical space in the list of figures, as this will be out of sync with the entries from the figures. Rather one can hook in to \begin{figure}.

The following is under the assumption, that you really want figure numbering to restart at the beginning of each appendix section. The resetting of the numbering can be achieved with

 \makeatletter\@addtoreset{figure}{section}\makeatother

Now vertical space between entries in lof is 10pt added via the \addvspace command. This may be inserted at the beginning of the first figure of a section with the help of \AtBeginEnvironment from the etoolbox package:

\AtBeginEnvironment{figure}{\ifnumequal{\value{figure}}{0}{\addtocontents{lof}{\protect\addvspace{10pt}}}{}}

This code tests if the current figure number is 0, it gets increased by 1 during the figure environment, and if so writes out the \addvspace code to the list of figures file.

Sample output

\documentclass{scrbook}

\usepackage{etoolbox}

\begin{document}
\listoffigures
\chapter{Lorem}
\begin{figure}[htb]
  \caption{1st lorum figure.}
\end{figure}
\begin{figure}[htb]
  \caption{2nd lorum figure.}
\end{figure}
\chapter{Ipsun}
\begin{figure}[htb]
  \caption{1st ipsum figure.}
\end{figure}
\begin{figure}[htb]
  \caption{2nd ipsum figure.}
\end{figure}
\chapter{Dolorem}
\appendix
\chapter*{Appendix}
  \renewcommand{\thesection}{\Alph{section}}
  \renewcommand{\thefigure}{\thesection.\arabic{figure}}
  \makeatletter
  \@addtoreset{figure}{section}
  \AtBeginEnvironment{figure}{\ifnumequal{\value{figure}}{0}{\addtocontents{lof}{\protect\addvspace{\@chapterlistsgap}}}{}}
  \makeatother
  \section{Lorem (Supplemental)}
    \begin{figure}[htb]
      \caption{1st lorum supp figure.}
    \end{figure}
    \begin{figure}[htb]
      \caption{2nd lorum supp figure.}
    \end{figure}
    \section{Ipsum (Supplemental)}
    \begin{figure}[htb]
      \caption{1st ipsum supp figure.}
    \end{figure}
    \begin{figure}[htb]
      \caption{2nd ipsum supp figure.}
    \end{figure}
    \section{Dolorem (Supplemental)}
\end{document}

Note the new numbering is reasonable; just look at the numbering you get if the main body sections contain different numbers of figures.

Note, \addvspace rather than \vspace is used, because it ensures that there is at least this amount of vertical space, rather than blindly adding more. This copes with sections that do not contain figures and with the 10pt already added by the \chapter* command.

Update following Ulrike's answer, we can see that the vertical gap is stored in \@chapterlistsgap, so the above code now uses that value instead of the fixed 10pt.

Related Question