3

I have a problem with the usage of the package caption with the package sidecap:

When I load the package caption with the package sidecap, the package caption shifts pictures in SCfigures a little bit to the right.

I didn't notice this because i was only using SCfigures with captions in my document... until i had to use a classic figure and put the caption below it, due to a longer text in the caption (which looked very packed and not very readable).

Now there's the point: the picture in the figure touches the left margin (which looks like the picture is set slightly more to the left than the text body), while the pictures in the SCfigures have that little gap to the left margin which looks like the picture is set with an indent.

I personally think this looks nice in my document, so i want the exact same gap with pictures in normal figures.

So my question is: Where does that gap come from and how big is it?

I googled for some time and I found screenshots of documents with sidecap where the picture is at the same horizontal position like it would be in a normal figure environment and screenshots which looked exactly like my problem... only difference was the caption package in the preamble of those examples online.

I know that the package caption is the reason. While writing the MWE I commented the line with \usepackage{caption} out and compiled again, et voilà, gap disappeared.

Anyway, here's my MWE:

\documentclass{article}
\usepackage{sidecap}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{showframe}
\begin{document}

\section{Example caption with SCfigure}
\begin{SCfigure}[50][h]
    \includegraphics[width=4cm]{example-image-a}
    \caption{Example for a caption going over more than one line. This sentence is just to make sure that it is really more than one line.}
\end{SCfigure}

\section{Example caption with figure}
\begin{figure}[h]
    \includegraphics[width=4cm]{example-image-a}
    \caption{Example for a caption going over more than one line. This sentence is just to make sure that it is really more than one line.}
\end{figure}

\section{Example caption with figure and manual space (cheap workaround)}
\begin{figure}[h]
    \hspace{6pt}\includegraphics[width=4cm]{example-image-a}
    \caption{Example for a caption going over more than one line. This sentence is just to make sure that it is really more than one line.}
\end{figure}

\end{document}

Previews:

with package caption:

with package caption

without package caption:

without package caption

2
  • 1
    You probably need to report it to the caption maintainer. Inside caption it contains some code that "patches" sidecap and somewhere that introduces an extra space.
    – daleif
    Jun 9, 2022 at 12:34
  • @daleif - I thought about that earlier but tex.stackexchange has a bit more reach (group intelligence). I'll wait a bit if somebody has an answer before reporting the issue to Gitlab, where possible bugs and suggestions are collected. Jun 10, 2022 at 7:03

2 Answers 2

1

OTOH, do you really need sidecap?

I would write a SCfigure replacement, but have no idea what function relwidth serves.

\documentclass{article}
%\usepackage{sidecap}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{showframe}

\begin{document}

\section{Example caption with SCfigure}
\begin{figure}[h]
\sbox0{\includegraphics[width=4cm]{example-image-a}}% measure width
\usebox0\hfill
\begin{minipage}[b]{\dimexpr \linewidth-\wd0-\columnsep}
  \captionsetup{skip=-\dp\strutbox}%
  \caption{Example for a caption going over more than one line. This sentence is just to make sure that it is really more than one line.}%
\end{minipage}
\end{figure}

\end{document}
6
  • +1: What is OTOH? Jun 9, 2022 at 21:39
  • 1
    @Dr.ManuelKuehner - On The Other Hand - At least it's not a TLA (Three Letter Acronym). Jun 9, 2022 at 21:46
  • @JohnKormylo - The parameter relwidth within the SCfigure environment defines the available horizontal space for the caption relative to the width of the picture. If not defined it is set to 1.0, which means that picture and caption are exactly the same width. (According to this the value 2 eg. makes the caption double as wide as the pic) In the package documentation the value 50 is recommended for reserving the maximum horizontal space for the caption, so i used it. Jun 10, 2022 at 6:44
  • So it automatically scales the image to fit the caption? Interesting! Actually, the tricky bit is implementing it as an environment. lrbox and varwidth might work. You would have to redefine \caption to save the arguments globally for later use. Jun 10, 2022 at 13:40
  • @JohnKormylo - The value doesn't modify the image. This is a try to make it visual in the comment: Value 1.0: (image 5cm width) ----- ----- (caption 5cm width); Value 2.0: (image 5cm width) ----- ---------- (caption 10cm width); very big value (eg. 50) (image 5cm width) ----- --------------| (caption uses all available space to the margin); And the author of sidecap used lrbox in the implementation... I'm just not the best in understanding the .sty files, so I couldn't help myself by analyzing those. Jun 13, 2022 at 7:05
0

I reported this issue to the author of caption on Gitlab.

If I find the answer there, I'll edit this 'answer' here to solve the problem.

Here is the outcome of my reported issue: The Gap I described is exactly one space big.

This solved at least one of my questions... the answer to the question where this gap come from lies somewhere deep in the code of LaTeX. (It has to do with spaces after commands and how LaTeX interprets those, as far as I could understand.)

Anyway, I'm happy enough, so I marked the question as solved.

You must log in to answer this question.

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