2

I am trying to adapt this solution (top option) for placing captions beside the figure. If I have one figure it works as expected, but when I try to add a second \includegraphics command to get an image immediately below the first - the spacing does not work as I expected (see figures below). How do I fix this? Or is there an alternative? I tried sidecap but it did not work for me.

1 figure 2 figures

MWE

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{floatrow}
\usepackage[showframe]{geometry}

\begin{document}

\begin{figure}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=0.4\textwidth}}]{figure}[\FBwidth]
{\caption{A test figure with its caption side by side - works fine if I only have one includegraphics}\label{fig:test}}
{\includegraphics[width=0.5\textwidth]{example-grid-100x100pt}}
\end{figure}

\begin{figure}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=0.4\textwidth}}]{figure}[\FBwidth]
{\caption{With two includegraphics everything is pushed to the right outside the page borders}\label{fig:test}}
{\includegraphics[width=0.5\textwidth]{example-grid-100x100pt} \\ \includegraphics[width=0.5\textwidth]{example-image-b}}
\end{figure}

\end{document}  
  • As it is, your code gives the following error message: Something's wrong--perhaps a missing \item.. Please never ever ignore error messages! Even if you get something that on first glance resembles a pdf file, there can still be issues with it. After an error, TeX only tries to recover enough to syntax check more of the file, it does not try to make sensible output after an error. – leandriis Sep 8 at 8:11
  • Are the two images suppose to only have a single caption? – leandriis Sep 8 at 8:13
  • The floatrow package tends to do strange things to captions. See tex.stackexchange.com/questions/403661/… – John Kormylo Sep 8 at 16:18
  • @leandriis the error message isn't being ignored - I just don't know how to fix things. If I knew how to fix it I wouldn't need to post on SE ;) And yes it's like the MWE - two images with a single caption. – Esme_ Sep 8 at 23:51
  • @Esme_: There was no hint on an error message in the question. This is why I initially expected the code to compile without errors but yielding the undesired output. My above comment was intended more like "don't worry about undesired outputs as long as there are error messages". – leandriis Sep 9 at 8:14
2

I suppose that your two images only have a single caption that is top aligned with the upper of the two images. In the following MWE, I have used a tabular to help position the images:

enter image description here

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{floatrow}
\usepackage[showframe]{geometry}

\begin{document}
\begin{figure}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=0.4\textwidth}}]{figure}[\FBwidth]
{\caption{With two includegraphics everything is pushed to the right outside the page borders}\label{fig:test}}
{\begin{tabular}{@{}l@{}}\includegraphics[width=0.5\textwidth]{example-grid-100x100pt} \\
\includegraphics[width=0.5\textwidth]{example-image-b}\end{tabular}
}
\end{figure}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.