目前,我想在圆圈内添加背景图像。为了简单起见,我在 MWE 中使用颜色。当我在背景上使用裁剪功能时,它们的工作方式与我预期的不同。
如何才能在背景上达到预期的效果?
这是我的 MWE:
\documentclass[border=1pt, tikz]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[
every circle/.style = {draw, radius=40mm}
, every node/.style = {rectangle, rounded corners, fill=white}
]
\coordinate (zero) at (0, 0);
\node at (zero) {A};
\draw (zero) ++(90:30mm) coordinate (circ1) circle ++(90:10mm) node {B};
\draw (zero) ++(270:30mm) coordinate (circ2) circle ++(270:10mm) node {C};
\begin{scope}[on background layer]
\path[clip] (circ1) circle;
\node[fill=blue, minimum size=100mm] at (circ1) {};
\end{scope}
\begin{scope}[on background layer]
\path[clip] (circ2) circle;
\node[fill=red, minimum size=100mm] at (circ2) {};
\end{scope}
\end{tikzpicture}
\end{document}
预期(删除“在背景层上”):
结果:
答案1
您添加的命令on background layer
将被累积起来并放在一张图片中。这意味着您需要额外的作用域环境:
\documentclass[border=1pt, tikz]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[
every circle/.style = {draw, radius=40mm}
, every node/.style = {rectangle, rounded corners, fill=white}
]
\coordinate (zero) at (0, 0);
\node at (zero) {A};
\draw (zero) ++(90:30mm) coordinate (circ1) circle ++(90:10mm) node {B};
\draw (zero) ++(270:30mm) coordinate (circ2) circle ++(270:10mm) node {C};
\begin{scope}[on background layer]
\begin{scope}
\path[clip] (circ1) circle;
\node[fill=blue, minimum size=100mm] at (circ1) {};
\end{scope}
\end{scope}
\begin{scope}[on background layer]
\begin{scope}
\path[clip] (circ2) circle;
\node[fill=red, minimum size=100mm] at (circ2) {};
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}