# Picture with grey box as background

Does anyone know how I can set up a grey box as background for my images like in this example in the picture below?

I had found a good example in Grey box code and lists but it doesn't work with a picture inside.

\documentclass{article}

\usepackage{color}
\definecolor{lightgray}{gray}{0.75}
\newcommand\greybox[1]{%
\vskip\baselineskip%
\par\noindent\colorbox{lightgray}{%
\begin{minipage}{\textwidth}#1\end{minipage}%
}%
\vskip\baselineskip%
}

\begin{document}
\greybox{Content of Grey Box}
...

// but it doesn't work with picture inside:

...
\greybox{
\begin{figure}[ht]
\footnotesize
\centering
\includegraphics[width=1.0\textwidth]{illustrationen/mygraphic.png}
\begin{flushright}
Some Reference
\end{flushright}
\caption{Title}
\label{fig:label}
\end{figure}
}

\end{document}

Anyone a simple idea for that?

You cannot enclose the figure environment within the argument to \greybox. Rather, enclose the contents of the figure environment within the argument to \greybox.

\documentclass{article}

\usepackage{color,graphicx}
\definecolor{lightgray}{gray}{0.75}
\newcommand\greybox[1]{%
\vskip\baselineskip%
\par\noindent\colorbox{lightgray}{%
\begin{minipage}{\textwidth}#1\end{minipage}%
}%
\vskip\baselineskip%
}

\begin{document}
\greybox{Content of Grey Box}
...

// but it doesn't work with picture inside:

...
\begin{figure}[ht]
\greybox{
\footnotesize
\centering
\includegraphics[width=1.0\textwidth]{example-image}
\begin{flushright}
Some Reference
\end{flushright}
\caption{Title}
\label{fig:label}
}
\end{figure}

\end{document}

You can do this easily using the adjustbox package. It gives you a bgcolor key for the background color. For multi-line content you need to use the minipage key first. You can also easily select the margin around the image by using the margin key. If all is \textwidth wide then you don't need to center the content, otherwise add the center key at the very end.

Forthermore, e.g. a frame could be easily added by using e.g. the frame key, in which case you should substract 2\fboxrule from the either the minipage width or the margin.

\documentclass{article}

\usepackage{xcolor}

\usepackage{mwe}% just for example text and images

\begin{document}
\lipsum[0-1]

\begin{figure}[ht]
\footnotesize
\adjustbox{right}{Some Reference}% add minipage=<width> before right if reference has multiple lines