![包含 tikz-feynman 的 tikz 图片中的背景颜色](https://linux22.com/image/374123/%E5%8C%85%E5%90%AB%20tikz-feynman%20%E7%9A%84%20tikz%20%E5%9B%BE%E7%89%87%E4%B8%AD%E7%9A%84%E8%83%8C%E6%99%AF%E9%A2%9C%E8%89%B2.png)
我正在尝试将下面的费南图的背景颜色分成两种不同的颜色(例如)上半部分为红色,下半部分为绿色. 请注意图中的水平线相互连接(这胶子行),因此它应该保留为单个 tikz 图片。
请注意,一般来说,我希望能够控制每种背景颜色(顶部和底部)的高度,这样它们就不一定是 50-50。到目前为止,我只能将单一颜色应用于整个背景,如下面的代码所示:
\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}
答案1
像这样吗?
\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}