# Subfigure package misplaces last subfigure in full width environment

I am using subfigure package along with pdflatex. My paper is in two columns, and sometimes I use a full width figure with subfigures:

\begin{figure*}
\subfigure[AM06]{\includegraphics[width=.25\textwidth]{AR06_RUN03_vort.png}}
\subfigure[AM07]{\includegraphics[width=.25\textwidth]{AR07_RUN03_vort.png}}
\subfigure[AM08]{\includegraphics[width=.25\textwidth]{AR08_run03_vort.png}}
\subfigure[AM09]{\includegraphics[width=.25\textwidth]{AR09_run03_vort.png}}
\subfigure[AM10]{\includegraphics[width=.25\textwidth]{AR10_run03_vort.png}}
\subfigure[AM11]{\includegraphics[width=.25\textwidth]{AR11_run03_vort.png}}
\subfigure[AM12]{\includegraphics[width=.25\textwidth]{AR12_run03_vort.png}}
\subfigure[AM13]{\includegraphics[width=.25\textwidth]{AR13_run03_vort.png}}
\end{figure*}


As you can see from the image, it places the last subfigure in the wrong position. Any ideas on how I can debug this?

• This may help: tex.stackexchange.com/a/207302/34618 – Jesse Dec 1 '14 at 8:17
• This depends a good deal on where you want subfigure (h) to be placed: exactly below subfigure (e), or the last two subfigures centered? – egreg Dec 1 '14 at 8:48

If you want the last row to be justified, with subfigure (h) exactly below subfigure (e), then this is a way:

\documentclass[twocolumn]{article}
\usepackage{subfig} % not subfigure!!!
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure*}
\setlength{\lineskip}{1ex}% increase spacing
\subfloat[AM06]{\includegraphics[width=.25\textwidth]{AR06_RUN03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM07]{\includegraphics[width=.25\textwidth]{AR07_RUN03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM08]{\includegraphics[width=.25\textwidth]{AR08_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM09]{\includegraphics[width=.25\textwidth]{AR09_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM10]{\includegraphics[width=.25\textwidth]{AR10_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM11]{\includegraphics[width=.25\textwidth]{AR11_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM12]{\includegraphics[width=.25\textwidth]{AR12_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM13]{\includegraphics[width=.25\textwidth]{AR13_run03_vort.png}}
\end{figure*}

\end{document}


Note that subfigure has been obsolete for 15 years.

If you prefer the last two subfigures to be centered in the line, just add \centering to the code above:

\documentclass[twocolumn]{article}
\usepackage{subfig} % not subfigure!!!
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure*}
\centering
\setlength{\lineskip}{1ex}% increase spacing
\subfloat[AM06]{\includegraphics[width=.25\textwidth]{AR06_RUN03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM07]{\includegraphics[width=.25\textwidth]{AR07_RUN03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM08]{\includegraphics[width=.25\textwidth]{AR08_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM09]{\includegraphics[width=.25\textwidth]{AR09_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM10]{\includegraphics[width=.25\textwidth]{AR10_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM11]{\includegraphics[width=.25\textwidth]{AR11_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM12]{\includegraphics[width=.25\textwidth]{AR12_run03_vort.png}}%
\hspace{.125\textwidth}%
\subfloat[AM13]{\includegraphics[width=.25\textwidth]{AR13_run03_vort.png}}
\end{figure*}

\end{document}


## A note about \lineskip.

When TeX forms a paragraph, it doesn't simply butt lines together, but inserts a vertical space between them, computed on the basis of the current value of \baselineskip. However, when the sum of the depth of a line with the height of the following line is more than \baselineskip, TeX inserts \lineskip.

In this case, due to the fact that all lines contain very high pictures, between any two lines in that single paragraph will have \lineskip between them. Increasing (locally) the value of \lineskip (default 1pt) does the trick of separating them.

• @Mico Why? Try the same code with 20ex instead of 1ex. It's \lineskip, not \parskip. – egreg Dec 1 '14 at 10:07
• @Mico I added some words about \lineskip. – egreg Dec 1 '14 at 10:14
• Thanks. That's great. I understand that subfigure is old - but it seems the easiest to use for this sort of thing? Is there an alternative that's just as simple? – James Dec 1 '14 at 21:46
• @James Either subfig (which changes \subfigure into \subfloat) or subcaption. – egreg Dec 1 '14 at 21:49

You haven't indicated how the last two subfigures should be placed, so I'll assume that they should be centered. This may be achieved by providing three \hspace*{\fill} instructions in the final row. (Rows 1 and 2 require only two \hspace*{\fill} instructions.)

Note that the subfigure package and its macros are deprecated. In the example below, I load the subcaption package instead and I use that package's subfigure environment.

\documentclass[twocolumn]{article}
\usepackage[demo]{graphicx}  % remove "demo" option in real document
\usepackage{subcaption}
\begin{document}
\begin{figure*}

%% first row
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR06_RUN03_vort.png}
\caption{AM06}\label{fig:AM06}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR07_RUN03_vort.png}
\caption{AM07}\label{fig:AM07}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR08_run03_vort.png}
\caption{AM09}\label{fig:AM08}
\end{subfigure}

%% second row
\medskip  %% add a bit of vertical separation from previous row
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR09_run03_vort.png}
\caption{AM09}\label{fig:AM09}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR10_run03_vort.png}
\caption{AM10}\label{fig:AM10}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR11_run03_vort.png}
\caption{AM11}\label{fig:AM11}
\end{subfigure}

%% final row
\medskip
\hspace*{\fill}
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR12_run03_vort.png}
\caption{AM12}\label{fig:AM12}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}{.25\textwidth}
\includegraphics[width=\linewidth]{AR13_run03_vort.png}
\caption{AM13}\label{fig:AM13}
\end{subfigure}
\hspace*{\fill}
\end{figure*}
\end{document}

• Don't advertise \null; most of all, don't use it yourself if you don't know what it does. Your first usage of \null is in vertical mode, so it does nothing at all (except perhaps some damage). Try without it and see. – egreg Dec 1 '14 at 8:57
• @egreg - Many thanks for pointing out this issue. Indeed, the output is the exactly the same without the first \null instruction. – Mico Dec 1 '14 at 9:09
• And now, \hfill\null should be \hspace*{\fill}: the latter is documented, the former isn't. – egreg Dec 1 '14 at 9:50
• @egreg - Thanks for this. I've replaced all \hfill instructions with \hspace*{\fill} and have gotten rid of the last \null directive. – Mico Dec 1 '14 at 9:58