Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Rounded corner colored box around figure
Make all figures and tables framed by default?

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?

share|improve this question
    
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
add comment

migrated from stackoverflow.com Dec 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., Seamus Jan 4 '12 at 13:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

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

enter image description here

\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
\DeclareColorBox{shaded}{\colorbox{black!15}}% Shade is 15% black
\floatsetup{framestyle=colorbox,colorframeset=shaded,framefit=yes,heightadjust=all,framearound=all}
\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}​
share|improve this answer
    
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
add comment

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}
\usepackage{adjustbox}

\begin{document}

\begin{figure}
\begin{adjustbox}{minipage=\linewidth-2\fboxrule,bgcolor=gray,frame}
    \centering
    \includegraphics[width=.8\linewidth,height=5cm]{file}
    \caption{Some caption}
\end{adjustbox}
\end{figure}

\begin{figure}
\begin{adjustbox}{minipage=\linewidth-4pt,margin=0pt 5pt,bgcolor=gray,frame=2pt}
    \centering
    \includegraphics[width=.8\linewidth,height=5cm]{file}
    \caption{Again with some vertical margin and thicker frame}
\end{adjustbox}
\end{figure}


% This should actually go to the preamble:
\newenvironment{myfigure}[1][tbhp]{%
    \begin{figure}[#1]%
    \begin{adjustbox}{minipage=\linewidth-4pt,margin=0pt 5pt,bgcolor=gray,frame=2pt}
        \centering
}{%
    \end{adjustbox}
    \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>.

Result

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.