[Tex/LaTex] Inserting subfigures

floatssubfloats

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}%
     %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(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}

Best Answer

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}%
     %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(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}

enter image description here