# Background colours in tikz picture containing tikz-feynman

I am trying to split the background colour of the Feynamn diagram below into 2 different colours with (for example) red in the top half and green in the bottom half. Note that both horizontal lines in the diagram are connected to each other (the gluon line) and therefore, it should remain with a single tikz picture.

Note that, in general, I would like to be able to control the height of each background colour (top and bottom) so they would not necessarily be 50-50. So far I've only been able to apply a single colour to the entire background as the code below shows:

\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{tikzpicture}[
show background rectangle,
background rectangle/.style={fill=red},
color=black]

\begin{feynman}

\vertex (a1);
\vertex[right=3cm of a1] (a2);
\vertex[below=2cm of a1] (b1);
\vertex[below=2cm of a2] (b2);
\diagram* { (a2) -- [fermion] (a1), (b1) -- [fermion] (b2), (b1) -- [gluon] (a2) };

\end{feynman}

\end{tikzpicture}
\end{document}


Something like this?

\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc}
\usepackage[compat=1.1.0]{tikz-feynman}
\begin{document}
\begin{tikzpicture}

\begin{feynman}

\vertex (a1);
\vertex[right=3cm of a1] (a2);
\vertex[below=2cm of a1] (b1);
\vertex[below=2cm of a2] (b2);
\diagram* { (a2) -- [fermion] (a1), (b1) -- [fermion] (b2), (b1) -- [gluon] (a2) };
\begin{scope}[on background layer]
\fill[red] (current bounding box.north west) rectangle
($(current bounding box.north east)!0.6!(current bounding box.south east)$);
\fill[blue] (current bounding box.south west) rectangle
($(current bounding box.north east)!0.6!(current bounding box.south east)$);
\fill[gray] ([yshift=1mm]$(current bounding box.north west)!0.6!(current bounding box.south west)$) rectangle
([yshift=-1mm]$(current bounding box.north east)!0.6!(current bounding box.south east)$);
\end{scope}
\end{feynman}

\end{tikzpicture}
\end{document}

• Almost! How would you make it so I can control the percentage of the background in red vs green? Right now the separation is exactly in the middle... – ranlot Apr 15 '18 at 14:20
• I updated it. Now its 60% red and 40% blue. By increasing/decreasing 0.6 in ($(current bounding box.north east)!0.6!(current bounding box.south east)$) you can change the percentage. – marmot Apr 15 '18 at 14:26
• Final thing I see now, How can you add a third colour? – ranlot Apr 15 '18 at 14:29
• @ranlot Where? In between? If so, what percentage? Which color? – marmot Apr 15 '18 at 14:31
• yes, in between. Let's say gray colour. Small percentage as kind of a "buffer zone" – ranlot Apr 15 '18 at 14:32