[Tex/LaTex] subcaption/subfigure not centered, and caption too narrow

horizontal alignmentsubcaptionsubfloats

I'm using the subcaption package to make some subfigures with subcaptions (clearly), in a two column document, specifically the IEEE Transactions journal document class.

There are a lot of figures, but some typical code for one of them is:

\begin{figure}
        \centering
        \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=65mm,clip=false]{figures/test_preds/s5_test_preds.pdf}
                \caption{Session 5 test data}
        \end{subfigure}
        ~

        \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=65mm,clip=false]{figures/test_preds/s32_test_preds.pdf}
                \caption{Session 32 test data}
        \end{subfigure}

        \caption{Label predictions using cross-correlation-, GTW-, and LSTM-based classifiers}
\end{figure}

Which produces the example on the left.

enter image description here

So not only do the images end up skewed to the right of the current column despite the \centering, but the subcaption is prematurely given a line break. The figure on the right has the same centering issue.

I should also mention that I'm only including \usepackage{subcaption}, as subcaption seems to subsume subfigure – Latex tells me I'm multiply defining subfigure if I \usepackage that as well.

Due to lack of time I'm tempted to solve this using \hspace (urgh), but it wouldn't solve the premature line-breaking of the subcaptions.

Best Answer

You have defined your subfigure environments to have a width of .3\textwidth, but your images are wider than that, so they will stick out on the right side. This is also the reason the captions are narrow, as they have the same width as the subfigures. So to fix this, just increase the width. You can use \columnwidth to make them as wide as the columns.

See the below code for an example, where I also added an \fbox around the each subfigure, so their boundaries are obvious.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
        \centering
        % this is wide enough
        \fbox{\begin{subfigure}[b]{\textwidth}
        \centering
                \includegraphics[width=7cm,clip=false]{example-image-a}
                \caption{Some long caption some long caption some long caption}
        \end{subfigure}}

        % this has a too narrow subfigure
        \fbox{\begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[width=7cm,clip=false]{example-image-b}
                \caption{Some long caption some long caption some long caption}
        \end{subfigure}}
        \caption{Label predictions using cross-correlation-, GTW-, and LSTM-based classifiers}
\end{figure}
\end{document}

enter image description here