4

I'm trying to put 2 images in a row with this code, and runs well, but... don't adapt the size of the last 2 images in a row.

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\includegraphics[width=\linewidth]{example-image-a}

\includegraphics[width=7.5cm]{example-image-b}

and now 2

\begin{figure}
\centering
\subcaptionbox{A cat\label{cat}}
[.45\linewidth]{\includegraphics{example-image-a}}
\subcaptionbox{An elephant\label{aaa1}}
[.45\linewidth]{\includegraphics{example-image-b}}
\caption{Two animals}\label{aaa2}
\end{figure}
\end{document}
  • you need to scale the images to the linewidth inside the figures \includegraphics[width=\linewidth]{...} – David Carlisle May 3 '14 at 16:12
6

At the time of inclusion, the images themselves have no idea about the box they may be contained within. So, you would need to set the width of each image individually. It's easier to just set [width=.45\linewidth] directly:

enter image description here

\usepackage{subcaption}
%...
\begin{figure}
  \centering
  \subcaptionbox{A cat\label{fig:cat}}
    {\includegraphics[width=.45\linewidth]{example-image-a}}
  \subcaptionbox{An elephant\label{fig:elephant}}
    {\includegraphics[width=.45\linewidth]{example-image-b}}
  \caption{Two animals}\label{fig:2animals}
\end{figure}

The space between the images is given by the line break between the \subcaptionboxes. If you wish to insert something more meaningful, see Reduction of Space between two Sub-figures.

3
\documentclass[12pt,a4paper]{article}
\usepackage[demo]{graphicx}%% delete [demo]
\usepackage{subcaption}
\begin{document}
\noindent
\includegraphics[width=0.49\linewidth]{ES-temperaturemap.eps}%
\hfill
\includegraphics[width=0.49\linewidth]{ES-temperaturemap.eps}

and now 2

\begin{figure}[!htb]
\centering
\subcaptionbox{A cat\label{cat}}[.45\linewidth]{%
  \includegraphics[width=0.45\linewidth]{ES-temperaturemap.eps}}
\subcaptionbox{An elephant\label{aaa1}}[.45\linewidth]{%
  \includegraphics[width=0.45\linewidth]{ES-temperaturemap.eps}}
\caption{Two animals}\label{aaa2}
\end{figure}
\end{document}

enter image description here

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.