[Tex/LaTex] Using subcaption package but subfigures end up stacked rather than side by side

graphicssubcaptionsubfloats

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.

Best Answer

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.