vertical alignment of captionbeside
KOMA-Script is a bundle of versatile LaTeX classes and packages
Brought to you by:
kohm
The vertical alignment of a picture and the corresponding label is wrong when a different font-size is selected for the figure caption. The following LaTeX-code demonstrates the problem:
\documentclass{scrarticle}
\setkomafont{caption}{\tiny}
\begin{document}
\begin{figure}
\begin{captionbeside}{This is a caption.}
\fbox{\Huge Picture}
\end{captionbeside}
\end{figure}
\end{document}
Without the line \setkomafont{caption}{\tiny}>
, both the baseline of the caption and the baseline of the word 'Picture' are perfectly aligned. However, with a different font size of the caption the two baselines are not aligned any more.
Milestone changed, because I cannot do any changes to already released KOMA-Script versions. So adding tickets to already closed milestone makes no sense. Please always use the default milestone.
Yes, I see. The problem is the alignment of boxes using boxes. The inner box of the caption uses the font size of element
caption
. The inner box of thecaptionbeside
content uses the font size of thecaptionbeside
content. But the outer boxes both use the font size offigure
environment. And because the inner boxes also use\ht\strutbox
(for top alignment) and\dp\strutbox
(for bottom alignment) to adapt the alignment, this cannot work correctly in this case.However, a change will be a little bit complicated. I also have to decide, which changes to already existing documents are tolerable and which should be avoided. I've to do some experiments with different cases to do a decision. And maybe the change should be done, depending on compatibility settings. So maybe I'll not change this until KOMA-Script 4.
Thank you the report.
Thank you very much for the explanation. I understand, that doing changes influencing existing documents is not a good option. That would have a negative impact on me, too, because I have a lot of documents where I tackled the problem by using \raisebox on the figure content with an experimentally determined value for the vertical shift.
However, for new documents, I would like to do it better. Do you have a proposal for a workaround? Based on your explanation, I came to the conclusion that setting the same font for the
captionbeside
content and thefigure
environment should fix the problem. This would make no difference for my applications since thefigure
content is almost always just an\includegraphics
command. However, the follwoing code results in a vertical misalignment, too:I think,
would work. And cross your fingers, it should still work, when I'll fix the issue. Unfortunately you cannot use LaTeX's new generic hooks to do this modification automatically.
BTW: Because
scrarticle
is officially not the same asscrartcl
, it could be, that with KOMA-Script 4 this name will be used for the incompatible successor ofscrartcl
. So if compatibility is a must, you should still usescrartcl
.Last edit: Markus Kohm 2022-11-10
Only to have a more complete test file:
And here is a first fix for it:
Note: The additional
\rule
in the caption is there only to illustrate the real height and depth of the caption line. I've also tested with several lines of caption text. And there it also seems to work.However, I still do not know, how I will add it, because the change will change already existing documents.
And another problem is, that this fix does not work, if package
caption
is loaded and currently I do not know, whether this is an issue of KOMA-Script or ofcaption
.See also my notes to [r3983].
Related
Commit: [r3983]
Issues:
#1Last edit: Markus Kohm 2022-11-10
Thanks a lot for the fix. I can use this as a good workaround for my own documents, because I do not use the package
caption
. However, I think it would be highly desirable to make the patch compatible with the packagecaption
since it is used by many people. Unfortunately, my LaTeX-knowledge is insufficient to help you in figuring out the cause of this problem.Regarding the question how to add the patch to KOMA-Script: Maybe you could add a KOMAoption (
baselinealignedbeside
or something similar).