[Tex/LaTex] Subfigures appearing offset

positioning

I have a figure made up of two subfigures but there is a slight vertical offset between the two.
Here's the code:

\begin{figure}[h!]
\centering
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\textwidth]{black body.png}
\caption{Theortical intensity of a black body white light source according to equation~\ref{eq:black body}}
\label{fig:black body}
\end{subfigure}
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\textwidth]{black body plus response.png}
\caption{white light source measured with system repsonse }
\label{fig:black body plus response}
\end{subfigure}
\caption[Black body measurement]{Intensity of a perfect black body measured in a system with an equal response over all wavelengths}\label{fig:black body comparison}
\end{figure}

Here's how it looks in the pdf:

enter image description here

It also offsets if I change both of the subfigures to the same figure so it isn't a problem with one of the images having more space or something.

Anyone have any ideas?

Thanks a lot

Best Answer

The problem is that one of the subcaptions has two lines and the other only one, and LaTeX is trying to vertically center both subfigures (subcaptions included). To solve it add [t] to \begin{subfigure}:

\begin{subfigure}[t]{0.49\textwidth}

MWE:

\documentclass[demo]{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}
\begin{document}
\begin{figure}[h!]
\centering
\begin{subfigure}[t]{0.49\textwidth}
\includegraphics[width=\textwidth]{black body.png}
\caption{Theortical intensity of a black body white light source according to equation~\ref{eq:black body}}
\label{fig:black body}
\end{subfigure}
\begin{subfigure}[t]{0.49\textwidth}
\includegraphics[width=\textwidth]{black body plus response.png}
\caption{white light source measured with system repsonse }
\label{fig:black body plus response}
\end{subfigure}
\caption[Black body measurement]{Intensity of a perfect black body measured in a system with an equal response over all wavelengths}\label{fig:black body comparison}
\end{figure}
\end{document}

enter image description here

Related Question