# How to add caption to graphics defined this way [duplicate]

I found this code here since it's exactly what I need to use, but also I need a caption under both of them. There is an example for a subcaption but that's not it. I simply tried to add the caption command but it doesn't work. Can someone tell me how to modify it? Thanks.

 \begin{center}
\resizebox{1.0\textwidth}{!}{
\includegraphics[height=3cm]{pic1}
% \caption{Picture 1}
\label{fig:pic1}
\includegraphics[height=3cm]{pic2}
% \caption{Picture 2}
\label{fig:pic2}
}
\end{center}


## marked as duplicate by Dr. Manuel Kuehner, Moriambar, TeXnician, Stefan Pinnow, MicoMay 16 '17 at 4:46

Instead \begin{center} ... \end{center} see if use package float and positioning option H in begin{figure}[H] ... \end{figure} is what you looking for:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}

\begin{document}
\begin{figure}[H]
\begin{subfigure}{0.45\linewidth}
\includegraphics[width=\linewidth]{pic1}
\caption{Picture 1}
\label{fig:pic1}
\end{subfigure}
\hfil
\begin{subfigure}{0.45\linewidth}
\includegraphics[width=\linewidth]{pic2}
\caption{Picture 2}
\label{fig:pic2}
\end{subfigure}
\caption{caption for both figure}
\label{fig:1-2}
\end{figure}
\end{document}