# Using subcaption package but subfigures end up stacked rather than side by side

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}
\end{figure}


Help would be greatly appreciated.

• 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 '14 at 3:48

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}
\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}

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