I learned from this answer to put a background color behind existing floats without having to change the content of these existing floats.
\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}
But the method here doesn't work for images drawn by tikzpicture, and I wonder how to achieve the same effect for tikzpicture.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\usetikzlibrary{calc}
\begin{tikzpicture}
\coordinate (center) at (3,3);
\coordinate (1) at (0,0);
\coordinate (2) at (5, .5);
\coordinate (3) at ($(center) +(30:2)$);
\coordinate (4) at ($(center) +(70:2)$);
\coordinate (5) at (0,6);
\draw[blue, dotted]
let \p1 = ($(3)-(center)$),
\n0 = {veclen(\x1,\y1)}
in (center) circle(\n0);
\filldraw[draw=black, fill=green, fill opacity=0.3]
let \p1 = ($(3) - (center)$),
\p2 = ($(4) - (center)$),
\n0 = {veclen(\x1,\y1)}, % Radius
\n1 = {atan(\y1/\x1)+180(\x1<0)}, % initial angle
\n2 = {atan(\y2/\x2)+180(\x2<0)} % Final angle
in
(1) -- (2) -- (3) arc(\n1:\n2:\n0) -- (5) -- cycle;
\foreach \dot in {1,2,3,4,5,center} {
\fill (\dot) circle(2pt);
\node[above] at (\dot) {\dot};
}
\end{tikzpicture}
\end{document}
Since I have a large number of files to work with, I would like the method to be more automated and not require me to manually insert many times. Looking forward to your answer!



tikzpictureis not a float. If you wrap yourtikzpicturein a\begin{figure}...\end{figure}float, and add the\makeatlettercode, it works as your prior example. – Steven B. Segletes Jan 02 '22 at 15:51