# Unable to use \subfloat

I am trying to put two figures in eps format side by side. I followed the example given in IEEE transaction template, but my latex throws this error. How can I put two figures side by side without wasting space / minimum acceptable space in between the two figures? Thank you

! Undefined control sequence.
<argument> \subfloat
[Case I]\includegraphics [width=2.5in]{Fig1a.eps}\lab...
l.20 \label{fig_first_case}}

?
! Emergency stop.
<argument> \subfloat
[Case I]\includegraphics [width=2.5in]{Fig1b.eps}\lab...
l.20 \label{fig_first_case}}

End of file on the terminal!


HEre is how I have done.

\documentclass[journal]{IEEEtran}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{epstopdf}
\DeclareGraphicsExtensions{.eps}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{amssymb}
\usepackage{amsmath,amscd}
\usepackage {extarrows}
\usepackage{epsf}
\usepackage{float}
\begin{document}
\begin{figure*}[!t]
\centerline{\subfloat[Case I]\includegraphics[width=2.5in]{Fig1a.eps}%
\label{fig_first_case}}
\hfil
\subfloat[Case II]{\includegraphics[width=2.5in]{Fig1b.eps}%
\label{fig_second_case}}}
\caption{Simulation results}
\label{fig_sim}
\end{figure*}
\end{document}

• You don't need graphics if you already have graphicx – user36296 Jun 3 '17 at 19:43
• Nor epsf which has been deprecated for more than 20 years, and replaced with graphicx. – Bernard Jun 3 '17 at 20:23

\documentclass[journal]{IEEEtran}
\usepackage{blindtext}
\usepackage[demo]{graphicx}
%\usepackage{epstopdf}
%\DeclareGraphicsExtensions{.eps}
\usepackage{amsmath, amsfonts, amssymb}
\usepackage{bm}
\usepackage{amscd}
\usepackage{extarrows}
%\usepackage{epsf}
%\usepackage{float}
\usepackage{subfig}

\begin{document}
\blindtext
\begin{figure*}
\centering
\subfloat[Case I    \label{fig_first_case}]{\includegraphics[width=2.5in]{Fig1a.eps}}
\hfil
\subfloat[Case II   \label{fig_second_case}]{\includegraphics[width=2.5in]{Fig1b.eps}}
%
\caption{Simulation results}
\label{fig_sim}
\end{figure*}
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\end{document}


don't gives any error. Differences to your MWE:

• added package subfig
• removed package graphics
• commented packages epstopdf, epsf, float wich aren't relevant for this case
• \centerline{...} is replaced with \centering

• Thank you so much!! IS there a way to reduce the white space between the two figures? – SKM Jun 3 '17 at 20:35
• @SKM, now the space around figures is equal distributed (depends from images width). If you like to have small space, than you repalce \hfil with desired space (for example defined with \hspace{<desired width> }. – Zarko Jun 3 '17 at 20:38

You need to use the subfig package which provides the \subfloat command. Did you 'just' copy and paste the code 'somewhere'?

Your error message says ! Undefined control sequence. <argument> \subfloat which literally means that the command is not known to your setup (because none of the packages you use define it).

• I did not use subfig package, should I simply use \usepackage{subfig}? Also, can you please say how to eliminate a lot of white space between the figure caption and the figure. I tried using \vspace{-0.9em} \caption{Result} \vspace{-1.0em} but, the white spaces did not go away – SKM Jun 3 '17 at 19:40
• also correct syntax to use \subfloat in your case is \subfloat[Case II]{\includegraphics[width=2.5in]{Fig1b}% \label{fig_second_case}} (see braces on the end and removed image extension). You can move label to inside of caption as: \subfloat[Case II \label{fig_second_case}]{\includegraphics[width=2.5in]{Fig1b}} – Zarko Jun 3 '17 at 19:42
• @Zarko: Should I write \usepackage{subfig}? This throws error saying unidentfied package detected – SKM Jun 3 '17 at 19:52
• @SKM, of course. In preamble of your document had to be \usepackage{subfig} ... – Zarko Jun 3 '17 at 19:59
• @Zarko: Thank you for your comments. I did put the package in the preamble, and removed the extra brace that you pointed out. But I am now getting these problems - Package caption Warning: Unsupported document class (or package) detected, (caption) usage of the caption package is not recommended. See the caption package documentation for explanation. – SKM Jun 3 '17 at 20:12