Distance between caption and table differs (scrbook)
[lt;dr] When text has to be put into a box, don't check the distances ;-)
Long explanation:
KOMA-Script has to put the caption text into a box to provide the given functionality. But TeX only has one baseline per box, and when you put text into a box, you have decide where to put the baseline, at the top or at the bottom line. Whatever you choose, the other distance will be incorrect.
Example code:
\documentclass{article}
\newcommand\testtext{This is a table with a very, very long caption that should span one line, and another line, perhaps even a third one.}
\begin{document}
\testtext\testtext\testtext
\vtop{\testtext\testtext\testtext}
\testtext\testtext\testtext
\vbox{\testtext\testtext\testtext}
\testtext\testtext\testtext
\end{document}
As you see the \vtop
will make the distance to the upper paragraph correct, but not the distance to the following paragraph. \vbox
will do the opposite.
One could try to correct this with a so-called strut, but when simply added by \strut
the outcome could be even worse:
\documentclass{article}
\newcommand\testtext{This is a table with a very, very long caption that should span one line, and another line, perhaps even a third one.}
\begin{document}
\testtext\AA{}\testtext\AA{}\testtext
\vtop{\testtext\AA{}\testtext\AA{}\testtext\strut}
\testtext\AA{}\testtext\AA{}\testtext
\vbox{\strut\testtext\AA{}\testtext\AA{}\testtext}
\testtext\AA{}\testtext\AA{}\testtext
\end{document}
The problem with \strut
is that it's like using a hammer to correct things here: It makes the distance usually too large instead of too small since it has the height and depth of the biggest character in font. Furthermore it operates in both directions, therefore changing the distance between lines in the text, too. (To make this even more worse, I added some \AA{}
to the text.) One can correct this by using \topstrut
resp. \bottomstrut
:
\documentclass{article}
\newcommand\testtext{This is a table with a very, very long caption that should span one line, and another line, perhaps even a third one.}
\makeatletter
\newcommand\topstrut{\vrule\@height\ht\strutbox\@width\z@}
\newcommand\bottomstrut{\@finalstrut\strutbox}
\makeatother
\begin{document}
\testtext\AA{}\testtext\AA{}\testtext
\vtop{\testtext\AA{}\testtext\AA{}\testtext\bottomstrut}
\testtext\AA{}\testtext\AA{}\testtext
\vbox{\topstrut\testtext\AA{}\testtext\AA{}\testtext}
\testtext\AA{}\testtext\AA{}\testtext
\end{document}
While this looks better that the previous example documents, we still have slightly different distances between the paragraphs. We can align this by using both in each box, \topstrut
and \bottomstrut
:
\documentclass{article}
\newcommand\testtext{This is a table with a very, very long caption that should span one line, and another line, perhaps even a third one.}
\makeatletter
\newcommand\topstrut{\vrule\@height\ht\strutbox\@width\z@}
\newcommand\bottomstrut{\@finalstrut\strutbox}
\makeatother
\begin{document}
\testtext\AA{}\testtext\AA{}\testtext
\vtop{\topstrut\testtext\AA{}\testtext\AA{}\testtext\bottomstrut}
\testtext\AA{}\testtext\AA{}\testtext
\vbox{\topstrut\testtext\AA{}\testtext\AA{}\testtext\bottomstrut}
\testtext\testtext\testtext
\end{document}
This looks best since the distance between the paragraphs are at least equal now. But they are (still) incorrect. And if you add another paragraph (without using a box) you'll see that the distance between the two ordinary paragraphs is slightly less that the distance between the other paragraphs. That's a major problem when using \strut
or something similar, you can't fix the problem but only trying to make it less annoying.
So the main problem is build into TeX itself. But why TeX only handles one baseline per box, and not two, an upper and a lower baseline? Because of the processor power and RAM amount available when TeX was written. So what we see here is a relic of the stone age of computing.
And what has this to do with KOMA-Script? When looking at the \caption
code of KOMA-Script one can see that it uses \vbox
internally and tries to correct distances using \strut
.
Update
The bug was fixed in KOMA-Script version 3.21 which is already on CTAN, in TeX Live 2016 and MiKTeX.
This is now a known issue of KOMA-Script version 3.20 (German). The official workaround at the moment is loading package caption
as I suggested in a comment.