Subfigure environment puts figures top and bottom, instead of side by side

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!

• Welcome to TeX.SE. Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – skpblack Oct 15 '14 at 4:37
• Well, you're using \caption in each subfigure instead of the option of the command \subfigure[caption] where you should add each subcaption, and the \caption is for the set of subfigures. Take a look that \subfigure is a command or macro, bot an environment. Maybe you're confused with the usage of the subfig packages that replaces the subfigure one that is deprecated. – Aradnix Oct 15 '14 at 4:41

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}


• Thank you very much. The first choice did the trick. If I may ask one more: In my initial snippet, I had extra line, between two subfigures. They did affect formatting, I think. In general, in Latex, should I avoid them? – ElectroJunkie Oct 15 '14 at 15:56
• Of course, an extra line means a change of paragraph, it is equivalent to \par. So the figures will be showed in different line. – skpblack Oct 15 '14 at 16:31
• Ah, thanks for your kind comments. Much appreciated! – ElectroJunkie Oct 15 '14 at 16:39