5

I would like to have two subfigures but on two rows. I tried with this code:

\documentclass[11pt,a4paper,titlepage]{report}  
\usepackage[T1]{fontenc}  
\usepackage[latin9]{inputenc}  
\usepackage{amssymb}  
\usepackage{graphicx}  
\usepackage{subcaption}  

\begin{document}  

\begin{figure}[h!]  
\centering  
\begin{subfigure}{.5\textwidth}  
  \centering  
  \includegraphics[width=1.8\linewidth]{image}  
    \caption{Caption for image 1}   
\end{subfigure}   

\begin{subfigure}{.5\textwidth}  
  \centering  
  \includegraphics[width=1.8\linewidth]{image}  
    \caption{Caption for image 2}   
\end{subfigure}  
\caption{A caption for both images}  
\end{figure}  
\end{document}  

The result is: both figures are aligned to the right side of the page while the caption of each figure is still in the center. Really appreciate if some one could help me!

Edit: Image of the result if this could help enter image description here

3

Well, 1.8\linewidth is 80% too wide for the current block (which is .5\textwidth wide), causing a problem. Try using only \linewidth or at least some portion of it.

enter image description here

\documentclass{report}
\usepackage{graphicx,subcaption}
\begin{document}

\begin{figure}[ht]
  \centering
  \begin{subfigure}{\linewidth}
    \centering
    \includegraphics[width=.8\linewidth]{example-image-a}
    \caption{Caption for image 1}
  \end{subfigure}

  \begin{subfigure}{\linewidth}
    \centering
    \includegraphics[width=.8\linewidth]{example-image-b}
    \caption{Caption for image 2}
  \end{subfigure}  
  \caption{A caption for both images}  
\end{figure}  
\end{document} 

Remember that \linewidth is a relative length. See Difference between \textwidth, \linewidth and \hsize.

  • I see! But the reason why I set that number so high because my figures are way too small. Do you have any suggestion how I can increase the size of the figures without causing the problem? – atn Aug 19 '13 at 17:55
  • 1
    @atn: You can scale them as I did. If you use \linewidth for the subfigure environment width, then the block containing the subfigure will be as wide as the text block. Then, relative to that width=.8\linewidth will scale the image to be 80% of the text block (enlarge/shrink). – Werner Aug 19 '13 at 18:00
  • 1
    @atn - Have you tried setting 0.9\textwidth (=0.5*1.8) or just \textwidth for the width of the subfigure environments? – Mico Aug 19 '13 at 18:02
  • Thank you both, Werner and Mico. I reduced 1.8\linewidth to something like 0.99\linewidth, then changed my old .5\textwidth for the subfigure environment to either \linewidth (as Werner said) or .9\textwidth (as Mico suggested). Both way work for me. – atn Aug 19 '13 at 18:35

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.