I'm trying to make all my figures (including caption) backgrounded with a decent color.

I already found these questions with some nice answers:

But all these answers have in common that they define some new environments or commands that need to be put inside the figures or replace the figures completly.

Is there a way to put a background color behind existing floats without having to change the content of these existing floats?

  • You can use the link answers. Just redefine the environment figure. – Marco Daniel Apr 4 '13 at 18:55
  • How about background color with adjustbox – texenthusiast Apr 4 '13 at 18:59

enter image description here



\def\@xfloat ##1[##2]{#1%
      \vbox \bgroup\aftergroup\egroup



\caption{yes no}

one two three

  • Thanks, how do select the float types (figure, table, ...) for which these apply? For example if I want different colors for figures and tables. – Foo Bar Apr 4 '13 at 19:07
  • \@captype will be figure table etc so you could test that or if it is just a matter of colour choice replace yellow by color-\@captype and then use \definecolor to define colors color-figure and color-table – David Carlisle Apr 4 '13 at 19:10
  • @DavidCarlisle, what is the meaning of !! on the 3rd line of the code? – Sigur Apr 4 '13 at 23:29
  • 1
    @Sigur It's just a token to mark the end of the argument (the end of the expansion of \@xfloat anything could be used that is not in the expansion of the macro so long as the same marker is used 6 lines later after the expansion of \@xfloat. – David Carlisle Apr 5 '13 at 0:09

Here is an elementary implementation using mdframed that redefines the figure environment (therefore not adapting the usage of figure in your document):

enter image description here

\usepackage{lipsum,mdframed,xcolor}% http://ctan.org/pkg/{lipsum,mdframed,xcolor}
\let\oldfigure\figure% Store old figure environment start
\let\endoldfigure\endfigure% Store old figure environment end
\renewenvironment{figure}[1][htbp]% Redefine figure
  \caption{This is a figure}

From here it would be straight forward to apply a different style to a different float (like table, for example).

  • Tried this, too. Worked well, hence the upvote, but I have accepted the other answer because it does not depend on a package (which could possbibly introduce unwanted side effects). – Foo Bar Apr 4 '13 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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