0

I am trying to plot two figures side by side and I simply can't find why my Output is stacking them on top of each other and not side by side. Any help would be greatly appreciated.

\documentclass[preprint,12pt]{elsarticle}
\usepackage{subcaption}
\usepackage{graphicx,caption}

\begin{figure}[t!]
\centering
\begin{subfigure}[b]{\linewidth}
    \centering
    \includegraphics[width=0.4\linewidth]{figures/coupling term graph}
    \captionsetup{width=0.4\linewidth}
    \caption{Plot of theoretical coupling term using the magnet and coil parameters given in table 1}
\end{subfigure}
\begin{subfigure}[b]{\linewidth}
    \centering
    \includegraphics[width=0.4\linewidth]{figures/coupling term superposition}
    \captionsetup{width=0.4\linewidth}
    \caption{Plot of theoretical coupling term using two identical magnets placed at each position for maximum flux for the coil parameters given in table 1}
 \end{subfigure}
\end{figure}

\end{document}

enter image description here

4
  • Welcome to TeX stack exchange. Could you edit your post to include a compilable minmal working example, starting with a \documentclass ending with a \end{document}. It will allow us to reproduce the behavior. Commented Nov 18, 2019 at 16:22
  • I added them, thanks for pointing that out.
    – Inf_E
    Commented Nov 18, 2019 at 16:29
  • 1
    Each subfigure is currently set to take up an entire row. Try using 0.4\linewidth for the width (and replace the 0.4\linewidth inside with either \linewidth or \textwidth). Commented Nov 18, 2019 at 16:32
  • Thanks! This solved it for me.
    – Inf_E
    Commented Nov 18, 2019 at 16:42

1 Answer 1

0

As per my comment. Note that [b] will align the bottoms of the captions, whereas [t] will align the bottoms (baselines) of the images.

\documentclass[preprint,12pt]{elsarticle}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}

\begin{figure}[tp]% ! doesn't do what you think it does
\centering
\begin{subfigure}[t]{0.4\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{Plot of theoretical coupling term using the magnet and coil parameters given in table 1}
\end{subfigure}\hfil% equal to outside spacing
\begin{subfigure}[t]{0.4\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-b}
    \caption[b]{Plot of theoretical coupling term using two identical magnets placed at each position for maximum flux for the coil parameters given in table 1}
 \end{subfigure}
\end{figure}

\end{document}

demo

You must log in to answer this question.

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