# How to calculate the width for placing 2 big images side by side?

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 at 16:12

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:

\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.

-
Yes, you´re right. My problem is typing[width...] before, because I view it in the fi4 in the loweer of page 7 in ctan.mirrorcatalogs.com/macros/latex/contrib/caption/… –  Mika Ike May 3 at 16:17
\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}


-
Yes, thank you. the problem was that I typed [width=...] before inlcudegrph... as I viewed in lower of page 7 in ctan.mirrorcatalogs.com/macros/latex/contrib/caption/… –  Mika Ike May 3 at 16:18
that width is only for the caption. –  Herbert May 3 at 16:19