# Inserting subfigures

I'm trying to insert a nested figure using the environment subfigure following the example in http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions#Subfloats

I added the following extra packages: \usepackage{subfigure}, \usepackage{caption} and \usepackage{subcaption}.

this is my MWE:

\begin{figure}
\begin{subfigure}%[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{SR4000}
\caption{SwissRanger by MESA}
\label{fig:SRl}
\end{subfigure}%
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}%[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{D-Imager}
\caption{D-Imager by Panasonic}
\label{fig:D-Imager}
\end{subfigure}
\caption{TOF depth cameras}\label{fig:TOF}
\end{figure}


but I am getting the following error

! Use of \@subfloat doesn't match its definition. \reserved@c
->\@subfloat {
sub\@captype }[\@empty {\@empty }][{\@empty }]
l.64                 \centering


line 64 here is:

\includegraphics[width=\textwidth]{SR4000}

-

Don't use subfigure and subcaption both. Also, subfigure is obsolete. Newer one is subfig.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.5\textwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{SwissRanger by MESA}
\label{fig:SRl}
\end{subfigure}%
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\caption{D-Imager by Panasonic}
\label{fig:D-Imager}
\end{subfigure}
\caption{TOF depth cameras}\label{fig:TOF}
\end{figure}
\end{document}


-
it worked with the packages you mentioned, but I had to add the {caption} package, but then when I compile i get an error that I cant find, it just tells me there are one error ' PDFTeXify Compilation Report (Pages: 45) Errors: 1 Warnings: 8 Bad Boxes: 8' –  SalamKh Nov 21 '12 at 13:08
And the error is  ! Package subcaption Error: This package can't be used in cooperation (subcaption) with the subfig package. –  Harish Kumar Nov 21 '12 at 13:15