# Background color boxes around complete figure in LaTeX [duplicate]

I'd like to make colored boxes (a light graytone) around my figures including the figure description in order to better enhance it from regular text.

Unfortunately, I don't have any idea how to accomplish this. Maybe someone can help?

-

## migrated from stackoverflow.comDec 30 '11 at 19:31

This question came from our site for professional and enthusiast programmers.

## marked as duplicate by Marco Daniel, Werner, lockstep, Torbjørn T., SeamusJan 4 '12 at 13:05

Welcome to TeX.sx! Your question was migrated here from StackOverflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Joseph Wright Dec 30 '11 at 19:34
@JosephWright: I know but this was my first hit. –  Marco Daniel Dec 30 '11 at 19:54
@JosephWright: I posted an answer in the meantime because Macro's link didn't really look like a full duplicate to me. Should this one be closed, please merge with question 31545. –  Martin Scharrer Dec 30 '11 at 19:56

Here is a minimal example, for reference, by virtue of floatrow and xcolor (for colour shades):

\documentclass{article}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx (don't use 'demo' in your document)
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{floatrow}% http://ctan.org/pkg/floatrow
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.6\linewidth]{image}
\caption{This is a caption.}
\label{fig:myfig1}
\end{figure}
See Figure~\ref{fig:myfig1}.
\end{document}​

-
This seems to work perfectly for figures. Does this also work for tables? And more importantly, for floating algorithm package? A quick test does not seem so... Also the documentation of floatrow states that there are some problems with the algorithm package... –  bwacx Dec 31 '11 at 12:46

You could use the adjustbox package/environment to draw a gray background and a frame around it. Either add an adjustbox environment to every figure or define your own environment as shown below:

\documentclass{article}
\usepackage[demo]{graphicx}% 'demo' in order to not require actual files to compile this example

\usepackage{xcolor}

\begin{document}

\begin{figure}
\centering
\includegraphics[width=.8\linewidth,height=5cm]{file}
\caption{Some caption}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=.8\linewidth,height=5cm]{file}
\caption{Again with some vertical margin and thicker frame}
\end{figure}

% This should actually go to the preamble:
\newenvironment{myfigure}[1][tbhp]{%
\begin{figure}[#1]%
\centering
}{%
\end{figure}
}
%%

\begin{myfigure}
\includegraphics[width=.8\linewidth,height=5cm]{file}
\caption{You can also define your own environment}
\end{myfigure}

\end{document}


See the adjustbox manual for all further usable keys. I can get a colored frame using cframe=<color>.

-