Figure
is a floating environment and minipage
is, unfortunately, not. Therefore, if you put a floating object inside a non-floating minipage
, you will get an error. But the other way around is possible--you can put a minipage
inside a figure
environment:
\begin{figure}
\centering
\begin{minipage}[c]{\textwidth}
\centering
\includegraphics[width=3.0in]{example-image-a}
\caption{Caption for image}
\label{fig:sample_figure}
\end{minipage}
\end{figure}
Another method is to avoid using figure
entirely. This can be done with help of the caption
package (with its captionof
facility, so that you can have a caption for the figure):
.....in preamble
\usepackage{caption}
......in document body
\begin{minipage}[c]{\textwidth}
\centering
\includegraphics[width=3.0in]{example-image-a}
\captionof{figure}{Caption for image}
\label{fig:sample_figure}
\end{minipage}
The total mwe will be:
\documentclass{article}
\usepackage{mwe} % new package from Martin scharrer
\usepackage{caption}
\begin{document}
\begin{figure}
\centering
\begin{minipage}[c]{\textwidth}
\centering
\includegraphics[width=3.0in]{example-image-a}
\caption{Caption for image}
\label{fig:sample_figure}
\end{minipage}
\end{figure}
\noindent
\begin{minipage}[c]{\textwidth}
\centering
\includegraphics[width=3.0in]{example-image-a}
\captionof{figure}{Caption for image}
\label{fig:sample_figure}
\end{minipage}
\end{document}
The result will be:
figure
is a float, it must be outside any other environment (not countingdocument
of course). Also check Keeping tables/figures close to where they are mentioned