1

I have written the following code in LaTeX which produces what is in the image below. My question is, how can I make it so that the two figures are in the same row, one next to the other? I have tried using minipage and subfigure but could not work it out. Thanks!

\begin{figure}
\begin{center}
\minipage{0.1\textwidth}
  \includegraphics[trim={0 2 2 2},clip,width=\linewidth]{image1.jpg}
\endminipage
\hspace{1 cm}
\minipage{0.1\textwidth}
  \includegraphics[trim={0 2 2 2},clip,width=\linewidth]{image2.jpg}
\endminipage
\caption{1st common caption}
\label{1st label}
\end{center}
\end{figure}

\begin{figure} \begin{center} \minipage{0.1\textwidth} \includegraphics[trim={0 2 2 2},clip,width=\linewidth]{image3.jpg} \endminipage \hspace{1 cm} \minipage{0.1\textwidth} \includegraphics[trim={0 2 2 2},clip,width=\linewidth]{image4.jpg} \endminipage \caption{2nd common caption} \label{2nd label} \end{center} \end{figure}

This is what the code produces

This is what I would like: enter image description here

Toni
  • 13
  • put them together in one figure environment. – Ulrike Fischer Jun 05 '23 at 13:44
  • @UlrikeFischer Thanks, I tried. But if I add \begin{figure} and \end{figure} at the top and bottom of the code, the error "Not in outer par mode" appears. If I remove the \end{figure} and \begin{figure} right in the middle of the code, the problem isn't solved; the two figures get closer together. – Toni Jun 05 '23 at 13:54
  • you can always add space between both e.g. with \vspace. – Ulrike Fischer Jun 05 '23 at 13:55
  • Take a look at the options in the floatrow package. An example of using that package to obtain a desired output can be found here: https://tex.stackexchange.com/questions/674888/subfigure-with-vertically-centered-subcaptions-on-the-side/674897#674897. There are other examples available too, I guess. – alchemist Jun 05 '23 at 14:08
  • @UlrikeFischer Yes, the thing is that they are still one below the other (not next to the other). I edited my post to show the desired result. – Toni Jun 05 '23 at 14:23
  • @alchemist Thanks! It looks like it is indeed possible to do it with floatrow (http://tug.ctan.org/macros/latex/contrib/floatrow/floatrow.pdf, page 101), but I think @\egreg found a simpler way. – Toni Jun 05 '23 at 14:35
  • sorry it wasn't clear that you want them side by side. – Ulrike Fischer Jun 05 '23 at 14:50

1 Answers1

0

Never use \minipage and \endminipage inside document. The two commands can be used for defining a new environment.

Now you can do the job using minipages, but in a different way.

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp] \centering

\begin{minipage}{0.4\textwidth} \centering

\includegraphics[width=0.25\linewidth]{example-image-9x16}% \hspace{1cm}% \includegraphics[width=0.25\linewidth]{example-image-9x16}%

\caption{1st common caption} \label{1st label}

\end{minipage}% \hspace{2cm}% \begin{minipage}{0.4\textwidth} \centering

\includegraphics[width=0.25\linewidth]{example-image-9x16}% \hspace{1cm}% \includegraphics[width=0.25\linewidth]{example-image-9x16}%

\caption{2nd common caption} \label{2nd label}

\end{minipage}

\end{figure}

\end{document}

enter image description here

egreg
  • 1,121,712