Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
you need to scale the images to the linewidth inside the figures \includegraphics[width=\linewidth]{...} –  David Carlisle May 3 at 16:12

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
    
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}

enter image description here

share|improve this answer
    
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
2  
that width is only for the caption. –  Herbert May 3 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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