[Tex/LaTex] Using subfloat to place figures side by side

document-classessubfloats

Hi am using the following code to place two figures side by side:

\usepackage{subfig}
\usepackage{graphicx}

%other part of code which compiles fine

\begin{figure}
     \centering
     \subfloat[][a]{\includegraphics{<figure1>}\label{<figure1>}}
     \subfloat[][b]{\includegraphics{<figure2>}\label{<figure2>}}
     \caption{Comparison of steady state results (a) x method (b) y method}
     \label{steady_state}
\end{figure}

%remaining part

this gives me an error: \subfloat outside float.

what would be incorrect in this ??

Best Answer

Please always post a complete document that shows the error. If I make a document from your posted fragments then I get no error, so presumably your error is in a part of your document you have not shown.

enter image description here

\documentclass{article}

\usepackage{subfig}
\usepackage[demo]{graphicx}

\begin{document}
other part of code which compiles fine

\begin{figure}
     \centering
     \subfloat[][a]{\includegraphics{<figure1>}\label{<figure1>}}
     \subfloat[][b]{\includegraphics{<figure2>}\label{<figure2>}}
     \caption{Comparison of steady state results (a) x method (b) y method}
     \label{steady_state}
\end{figure}
%remaining part

\end{document}

If you can reproduce the error please edit your question to include a document that shows the problem.