# subcaption/subfigure not centered, and caption too narrow

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.

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.

• Have you checked the bounding box size? Maybe there is white space on the left skewing it right. – dustin Aug 14 '13 at 15:13
• Don't think so...imgur.com/PWQPRWr – normally_deviated Aug 14 '13 at 15:21
• Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. – Claudio Fiandrino Aug 14 '13 at 15:34
• @dustin, what I mean to say is: I'm not sure how to check the bounding box, but that looks like one. Also, in the pdf of the graphic, there is no whitespace, and I'm not adding any in code so...stuck. – normally_deviated Aug 14 '13 at 15:49
• Do \fbox{\includegraphics[]{}} Then post that image. – dustin Aug 14 '13 at 15:50

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}


• Thanks! That solved it. I would've thought subfigure might have truncated the graphics or something, rather than just let it hang out. – normally_deviated Aug 15 '13 at 12:08