3

I have some code that used to work correctly on some other machine, but I currently have an issue with subfloat captions: They appear next to the image (on the left side) instead of below. Here is a minimal exemple:

\documentclass[a4paper,twoside,12pt]{memoir}
\usepackage{graphicx}
\usepackage{float}
%\usepackage{subfig}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\subfloat[subcap 1]{\includegraphics[width=0.48\linewidth]{example-image-a}}
\subfloat[subcap 2]{\includegraphics[width=0.48\linewidth]{example-image-b}}
\caption{caption}
\end{figure}
\end{document}

And here is the result:

subcaption_bug

I managed to get the result I want using the subcaption package, with the following syntax:

\begin{figure}
\centering
\begin{subfigure}{0.48\linewidth}
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{subcap 1}
\end{subfigure}
\end{figure}

With subfig, it works as expected. But I have a very big document, with other commands that are specific to subcaption. I don't want to have to change everything if I can help it... I'm getting confused between all different subfloat packages. I only find information on subfig or subcaption.

What can I do?

Thanks!

5
  • 2
    Welcome to TEX.SX! Your code is fine. Just add the required package (subcaption or subfig).
    – Imran
    Nov 29, 2021 at 16:32
  • Thank you for your answer. Actually, yes, I forgot to mention I was using subcaption in my doc. But when I add it to the above exemple, it produces the same result. Subfig works indeed, but I would still have to change a lot of stuff, and I am using hyperref, I read they are not compatible. I will give it a try though. But I would like to understand why it stopped working correctly with subcaption.
    – Elensil
    Nov 30, 2021 at 8:54
  • 1
    Here (imgur.com/cDebw4v) is what I got after adding the subcaption package. The output seems ok. I am not sure but maybe there are some other issues. You may try to reproduce the error and show here.
    – Imran
    Nov 30, 2021 at 11:07
  • 1
    Thanks, I edited my question to include the output. I found an acceptable solution by using subfig, and replacing calls such as \begin{subfigure} by \begin{minipage}. I have a document very similar to what I expect with mininal changes to the code. But still, I would be interested to understand where my problem comes from. I just installed the latest version of MikTeX, and I am using a recent install of TexMaker as well, which downloads package automatically. If it can help...
    – Elensil
    Nov 30, 2021 at 12:47
  • 1
    You are right, although the documentation for the subcaption package tells us that it provides a command \subfloat for compatibility reasons that should behave exactly like the macro with the same name from the subfig package, as of TeXLive 2021, this seems not to work. With older installations, however, it works. I don't exactly know why this is. Nov 30, 2021 at 13:14

1 Answer 1

2

Note that the subfigure package is deprecated and its successor, the subfig package, was last updated in 2005.

Therefore, I suggest you just use the preferred syntax for the subcaption package:

\documentclass[a4paper,twoside,12pt]{memoir}
\usepackage{graphicx}
\usepackage{float}
%\usepackage{subfig}
\usepackage{subcaption}

\begin{document}
\begin{figure}
\centering
\subcaptionbox{subcap 1}{\includegraphics[width=0.48\linewidth]{example-image-a}}
\subcaptionbox{subcap 2}{\includegraphics[width=0.48\linewidth]{example-image-b}}
\caption{caption}
\end{figure}
\end{document}

enter image description here

1
  • Thanks for the clarification. I didn't know the subcaptionbox command. I wonder why they changed the bracket style, but at least, I can get my code running with minimal changes.
    – Elensil
    Nov 30, 2021 at 14:13

You must log in to answer this question.

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