[Tex/LaTex] Subfigure environment puts figures top and bottom, instead of side by side

subcaptionsubfloats

This question was asked, but I don't seem to resolve my case by adapting solutions from others.

I am simply trying to put two figures side by side. However, regardless of the linewidth setting, my figures constantly placed top and bottom. My code is very simple.

\begin{figure}[h!]

\centering
\begin{subfigure}{.5\linewidth}
    \includegraphics[width=\linewidth]{pic1.jpg}
    \caption{pic1caption}
\end{subfigure}

\begin{subfigure}{.5\linewidth}
    \includegraphics[width=\linewidth]{pic2.jpg}
    \caption{pic2caption.jpg}
\end{subfigure}

\caption{Figure caption}

\end{figure}

Any help / pointer would be appreciated!

Best Answer

You have two options:

  • Omit the space between the two subfigures putting a % symbol after of the first \end{subfigure} (i.e \end{subfigure}%).

  • Reduce the width of the subfigures for example to 0.45\linewidth, (i.e. \begin{subfigure}{.45\linewidth}). This allows to keep the space between both subfigures without forcing a change of line.

    \documentclass{article}
    \usepackage{caption,subcaption}
    \usepackage{graphicx}
    \begin{document}
    \begin{figure}[h!]
    \centering
    \begin{subfigure}{.45\linewidth}
        \includegraphics[draft,width=\linewidth]{pic1.jpg}
        \caption{pic1caption}
    \end{subfigure} 
    \begin{subfigure}{.45\linewidth}
        \includegraphics[draft,width=\linewidth]{pic2.jpg}
        \caption{pic2caption.jpg}
    \end{subfigure}
    \caption{Figure caption}
    \end{figure}
    \end{document}
    

enter image description here

Related Question