# Subfigure have problems putting figures in the same line

I am using the IEEEtran template, two columns. When I want to put 4 figures in the same line (spanning two columns) using the \subfigure package, with the width of each figure setting to 0.24\textwidth, these four figures cannot be placed in the same line. (see below latex code and the resulting figure.)

\begin{figure*}[!t]
\centering
\begin{minipage}[htp]{1\textwidth}
\subfigure[\footnotesize x1.]{
\includegraphics[width=0.24\textwidth]{x1.eps}
\label{fig:x1}
}
\hfill
\subfigure[\footnotesize x2.]{
\includegraphics[width=0.24\textwidth]{x2.eps}
\label{fig:x2}
}
\hfill
\subfigure[\footnotesize x3.]{
\includegraphics[width=0.24\textwidth]{x3.eps}
\label{fig:x3}
}
\hfill
\subfigure[\footnotesize x4.]{
\includegraphics[width=0.24\textwidth]{x4.eps}
\label{fig:x4}
}
\vspace{-0.2cm}
\caption{\footnotesize xxxx.}\label{xxxx}
\end{minipage}
\end{figure*}


However, when I do not use the \subfigure package, 4 figures can be correctly reside in one line. (see below)

   \begin{figure*}[!t]
\centering
\begin{minipage}[htp]{0.24\textwidth}
\centering
\includegraphics[width=1\textwidth]{x1.eps}
\vspace{-0.6cm}%
\caption{\footnotesize x1.}
\label{fig:x1}
%\vspace{-0.2cm}%
\end{minipage}
\centering
\begin{minipage}[htp]{0.24\textwidth}
\centering
\includegraphics[width=1\textwidth]{x2.eps}
\vspace{-0.6cm}%
\caption{\footnotesize x2.}\label{fig:x2}
%\vspace{-0.2cm}%
\end{minipage}
\begin{minipage}[htp]{0.24\textwidth}
\centering
\includegraphics[width=1\textwidth]{x3.eps}
\vspace{-0.6cm}%
\caption{\footnotesize x3.}
\label{fig:x3}
%\vspace{-0.2cm}%
\end{minipage}
\centering
\begin{minipage}[htp]{0.24\textwidth}
\centering
\includegraphics[width=1\textwidth]{x4.eps}
\vspace{-0.6cm}%
\caption{\footnotesize x4.}\label{fig:x4}
%\vspace{-0.2cm}%
\end{minipage}
\vspace{-0.3cm}%
\end{figure*}


Why the same width leads to different formats?

Edit: I have upload the tex and eps files to here: http://pan.baidu.com/share/link?shareid=1594110695&uk=3776487005, which compose a MWE. Please open that link and click the button as shown in the figure below to download. (The opened page will be in Chinese.)

• And don't use [!t] with starred figure environment. Let it handle by itself. – percusse Jul 14 '13 at 12:45

Inside subfigure, you're in horizontal mode, so you need to be careful of escaping your line ends. Where you have

\subfigure[\footnotesize x1.]{
\includegraphics[width=0.24\textwidth]{x1.eps}
\label{fig:x1}
}


you insert an additional space character every time a line doesn't end with %, and this is inserting just enough space to cause the boxes to overfill the line; see below.

\documentclass[a4paper]{article}
\usepackage[draft]{graphicx}
\usepackage{subfigure}
\begin{document}
\begin{figure*}
\centering
\subfigure[x1.]{%
\includegraphics[width=0.24\textwidth]{x1.eps}%
\label{fig:x1}%
}%
\hfill
\subfigure[x2.]{%
\includegraphics[width=0.24\textwidth]{x2.eps}%
\label{fig:x2}%
}%
\hfill
\subfigure[x3.]{%
\includegraphics[width=0.24\textwidth]{x3.eps}%
\label{fig:x3}%
}%
\hfill
\subfigure[x4.]{%
\includegraphics[width=0.24\textwidth]{x4.eps}%
\label{fig:x4}%
}%
\caption{xxxx.}
\label{xxxx}
\end{figure*}
\end{document}


As a side-note, you shouldn't be manually changing the font size inside each caption. Use the caption package (etc.) to do this automatically across your whole document.

• Thank you so much! I didn't have any idea about the horizontal mode before, nor did I know % can be used in such a way. And I am sure that this is not the first time I am suggested not to manually change the font size. But I don't know how to use the caption package. – Bloodmoon Jul 14 '13 at 14:19
• If you're using the IEEEtran class because you're submitting to a journal or conference, best not to adjust things like font style anyway since they'll do that themselves when they publish the paper. – Will Robertson Jul 16 '13 at 2:41