24

I'm trying to put two jpegs side by side using the subcaption package, but the images are consistently stacking on top of each other rather than side by side. All the solutions I've found simply state that the pictures have to be small enough to actually be side by side but I've tried making them smaller, too small even and they stay stacked. My code looks like this:

\begin{figure}[H]
\centering
\begin{subfigure}{0.5\textwidth}
\centering
    \includegraphics[width=0.3\linewidth]{inclusion.jpg}
    \caption{inclusions}
    \label{fig:inclu}
\end{subfigure}

\begin{subfigure}{0.5\textwidth}
\centering
    \includegraphics[width=0.3\linewidth]{deform}
    \caption{grain deformation}
    \label{fig:deform}
\end{subfigure}
\caption{filler text}
\label{fig:manmade}
\end{figure}

Help would be greatly appreciated.

1
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Adam Liter
    Feb 26, 2014 at 3:48

1 Answer 1

23

Don't leave blank lines in between (a blank line tantamounts to \par, so the next subfigure starts a new paragraph), and remove spurious blank spaces (see the % after the first \end{subfigure}):

\begin{figure}[H]
\centering
\begin{subfigure}{0.5\textwidth}
\centering
    \includegraphics[width=0.3\linewidth]{inclusion.jpg}
    \caption{inclusions}
    \label{fig:inclu}
\end{subfigure}%
\begin{subfigure}{0.5\textwidth}
\centering
    \includegraphics[width=0.3\linewidth]{deform}
    \caption{grain deformation}
    \label{fig:deform}
\end{subfigure}
\caption{filler text}
\label{fig:manmade}
\end{figure}

A complete example:

\documentclass{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx}

\begin{document}

    \begin{figure}[H]
    \centering
    \begin{subfigure}{0.5\textwidth}
    \centering
        \includegraphics[width=0.3\linewidth]{inclusion.jpg}
        \caption{inclusions}
        \label{fig:inclu}
    \end{subfigure}%
    \begin{subfigure}{0.5\textwidth}
    \centering
        \includegraphics[width=0.3\linewidth]{deform}
        \caption{grain deformation}
        \label{fig:deform}
    \end{subfigure}
    \caption{filler text}
    \label{fig:manmade}
    \end{figure}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

2
  • Wow, I feel pretty silly now. Thanks so much! Feb 26, 2014 at 3:21
  • @GonzaloMedina great point "... remove spurious blank spaces (see the % after the first \end{subfigure} ...". This explains why my attempts to have subfigures each composed of a figure and aligned LaTeX were stacked vertically instead of presented side-by-side as desired. Jul 1, 2014 at 5:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .