[Tex/LaTex] Background color for existing floats (e.g. w/o defining a new environment)

backgroundscolorfloats

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?

Best Answer

enter image description here

\documentclass{article}

\makeatletter

\def\foo#1\normalcolor\vbox\bgroup#2!!{%
\def\@xfloat ##1[##2]{#1%
 \normalcolor
      \hbox\bgroup{\color{yellow}\leaders\vrule\hskip\columnwidth\hskip-\columnwidth}%
      \vbox \bgroup\aftergroup\egroup
#2}}
\expandafter\foo\@xfloat{#1}[#2]!!

\makeatother

\usepackage{color}
\begin{document}

\begin{figure}
a\\b\\c
\caption{yes no}
\end{figure}

one two three

\end{document}
Related Question