I am using following code to import two images next to each other. When \caption{} is used, LaTeX gives me error caption outside float.
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.5\textwidth]{fig1.eps}
\caption{text for fig1}
\label{fig:fig1}
\end{minipage}
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.5\textwidth]{fig2.eps}
\caption{text for fig2}
\label{fig:fig2}
\end{minipage}
When I remove the \caption from both places, the code compiles correctly.
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.5\textwidth]{fig1.eps}
\label{fig:fig1}
\end{minipage}
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.5\textwidth]{fig2.eps}
\label{fig:fig2}
\end{minipage}
But both the codes do not generate any label naming the figure. (something like Figure 21).
Am I missing anything?