Subfigures are coming out strangely staggered, I want them to be side by side

subcaptionsubfloats

I'm trying to place two subfigures side by side and for some reason the output is staggered and I don't understand why.

Code

\begin{figure}[t!]
\centering
\begin{subfigure}[a]{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{images/Mu2W625N.png}
    \caption{Fit for $\mu$}
    \label{fig:muscot}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{images/Sigma2W625N.png}
    \caption{Fit for $\sigma$}
    \label{fig:sigmascto}
\end{subfigure}
\caption{Fits for $\mu$ and $\sigma$ against the data, with respective R squared values of 0.99 and 0.98}
\label{fig:musigmascot}
\end{figure}

But the output looks like this

Output

I can't work out why, I've tried a few things related to help for when the captions are causing them not to line up properly (eg, the [t!]) which hasn't worked, I haven't been able to find any posts about the problem as I have it (the output being weirdly staggered).

I don't believe it's the images, neither has a massive white space above it and I've tried with different images and putting images as the same source graphic but they all result in the same staggering issue.

I'm using overleaf if that matters. I have copy pasted the code from the overleaf documentation for side by side figures and just updated with my own figures and captions.

Best Answer

[a] and [b] are NOT meaning what you think. The optional argument to subfigure is a vertical alignment. Your valid choices are [t], [c], or [b] (and also [T] and [B], see documentation, https://ctan.org/pkg/subcaption).

[a] is invalid and thus ignored, giving instead the default vertically centered alignment. [b] means "bottom" and so the image is bottom aligned. Thus, in the OP's invocation, the center of the left image aligns with the bottom of the right image, which is not what you wanted but indeed what you asked for.

\documentclass{article}
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure}[t!]
\centering
\begin{subfigure}{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Fit for $\mu$}
    \label{fig:muscot}
\end{subfigure}
\hfill
\begin{subfigure}{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Fit for $\sigma$}
    \label{fig:sigmascto}
\end{subfigure}
\caption{Fits for $\mu$ and $\sigma$ against the data, with respective R squared values of 0.99 and 0.98}
\label{fig:musigmascot}
\end{figure}
\end{document}

enter image description here