7

I have found several posts and questions from people wanting to remove the vertical spacing automatically added to the list of figures, but my problem is (exactly) the opposite:

I'm using the scrartcl document class with sections as the highest level seperator. In my list of figures there is no separation between the figures of different sections.

How can I add such a visual separation?

See the following minimal working example and the output below:

\documentclass[11pt,a4paper]{scrartcl}

\usepackage{amsmath}

\numberwithin{figure}{section}

\begin{document}

\listoffigures

\section{Section}

\begin{figure}[ht]\caption{Figure}\end{figure}
\begin{figure}[ht]\caption{Figure}\end{figure}

\section{Section}

\begin{figure}[ht]\caption{Figure}\end{figure}

\end{document}

output of the mwe

3
  • Welcome to TeX.SX! Nice question!
    – egreg
    Sep 29, 2014 at 15:08
  • Indeed a very good question, but be aware that classes witch chapters provide this feature by default. KOMA provides its own interface with the key listof and values like chaptergapline, chaptergapsmall or nochaptergap.
    – Johannes_B
    Oct 3, 2014 at 7:44
  • @Johannes_B Yes, I'm aware that for example scrbook adds this automatically, but since I'm using scrartcl this is not the case. But a good addendum for future readers.
    – Artemis
    Oct 3, 2014 at 11:38

1 Answer 1

7

You need to patch the \@startsection command; patching \section is also possible, but it would add a spacing command also for \section*. Not a big deal, but if it's possible to avoid it, the better.

\documentclass[11pt,a4paper]{scrartcl}

\usepackage{amsmath}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\@startsection}
  {\@dblarg}
  {\artemis@space@loft{#2}\@dblarg}
  {}{}
\newcommand{\artemis@space@loft}[1]{%
  \ifnum#1=\sectionnumdepth
    \doforeachtocfile[float]{%
      \addtocontents{\@currext}{\protect\addvspace{\@sectionlistsgap}}%
    }%
  \fi
}
\newcommand{\@sectionlistsgap}{5pt} % <-- change here the desired gap
\makeatother

\numberwithin{figure}{section}

\begin{document}

\listoffigures

\section{Section}

\begin{figure}[ht]\caption{Figure}\end{figure}
\begin{figure}[ht]\caption{Figure}\end{figure}

\section{Section}

\subsection{SUB}

\begin{figure}[ht]\caption{Figure}\end{figure}

\end{document}

Explanation: \@dblarg is executed only when we have \section without *; so, before TeX executes it, we add \artemis@space@loft, that adds a vertical space annotation in the .lof and .lot files. This is the same as the book class does for \chapter (10pt is used there, in an article a smaller space seems more appropriate). It uses a technique suggested by Johannes_B that exploits a feature of Koma-Script; in this way also newly defined float types will get the same treatment.

Parameter #2 to \@startsection is the section level, so we check it's the same as \sectionnumdepth. For article one should use \@ne instead of \sectionnumdepth in the body of \artemis@space@loft.

I added \subsection in order to check that the spacing is added only for sections (and it is).

enter image description here

Important update for KoMaScript version 3.14

When the newly released version 3.14 of KoMaScript classes and packages has been installed, the above patch doesn't work any more.

For this version one has to change

\patchcmd{\@startsection}
  {\@dblarg}
  {\artemis@space@loft{#2}\@dblarg}
  {}{}

into

\patchcmd{\scr@startsection}
  {\scr@section@dblarg}
  {\artemis@space@loft{#2}\scr@section@dblarg}
  {}{}

Thanks to Johannes_B for having noticed it so early (the new version was uploaded in TeX Live on December 8, 2014).

If both patches are necessary for a cooperative job when one of the parties has not yet updated KoMaScript, then

\makeatletter
\ifdefined\scr@startsection
  \patchcmd{\scr@startsection}
    {\scr@section@dblarg}
    {\artemis@space@loft{#2}\scr@section@dblarg}
    {}{}
\else
  \patchcmd{\@startsection}
    {\@dblarg}
    {\artemis@space@loft{#2}\@dblarg}
    {}{}
\fi
\newcommand{\artemis@space@loft}[1]{%
...

should do.

3
  • Thank you very much. Very nice answer, good explanation and (of course) it works nicely. :-)
    – Artemis
    Sep 29, 2014 at 15:24
  • @Artemis From your profile I learned you're not a TeX.SX newbie, so the welcome is late. Surely it was a very well posed question. Thanks for the contribution: your question seems to be useful.
    – egreg
    Sep 29, 2014 at 15:27
  • Well, I've always had a look at tex.sx q&a when looking for solutions for problems I encountered. But since this is my first question here (so kind of a newbie), giving me a nice welcome was still appropriate.
    – Artemis
    Sep 30, 2014 at 7:28

You must log in to answer this question.

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