[Tex/LaTex] How to place two figures side by side with subcaption

subcaptionsubfloats

I am trying to display two figures next to each other with captions using subfigures but it keeps placing one under the other.

Here is my code:

\documentclass{article}

\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering

\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[width=0.7\linewidth]{apparatus.jpg}
\caption{A photograph of the apparatus used}
\label{fig:capparatus}
\end{subfigure}

\begin{subfigure}{0.5\textwidth}
\centering
\def\svgwidth{0.7\linewidth}
\input{diagram.pdf_tex}
%\includegraphics[width=0.7\linewidth]{diagram.pdf}
\caption{A diagram of the apparatus sited inside the evacuated chamber}
\label{fig:cdiagram}
\end{subfigure}

\caption{A graphical depiction of the setup}
\label{fig:csetup}
\end{figure}

\end{document}

I have tried:

  • Changing from pdf_tex to just including the pdf file (generated from inkscape)
  • Adding [h] and [b] to the subfigures
  • Adding a % after the first and second subfigures
  • Changing the sizes of the subfigures and images

but nothing seems to make them display on the same line. Does anyone know how to do this?

Here is my output with pdf_tex:

With pdf_tex

And with just the pdf:

Without pdf_tex

Best Answer

To display images side by side it is preferable to use the subfig package instead of the subcaption package. You must not put a space between the two calls to subfloat

\documentclass{article}

\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{subfig}

\begin{document}

\begin{figure}

\centering
\subfloat[A photograph of the apparatus used]{\label{fig:capparatus}
\centering
\includegraphics[width=0.45\linewidth]{apparatus.jpg}
}
%no space
\hfill
\subfloat[A diagram of the apparatus sited inside the evacuated chamber]{\label{fig:cdiagram}
\centering

\includegraphics[width=0.45\linewidth]{diagram.pdf}
}

\caption{A graphical depiction of the setup}
\label{fig:csetup}
\end{figure}

\end{document}

enter image description here