0

Currently, I would like to include background images in circles. For the sake of simplicity, I use colors in the MWE. When I use clipping in scopes on backgrounds they work in a different way than I expect.

How can I achieve the expected result on backgrounds?

Here is my 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}

Expected (remove "on background layer"):

Expected

Result:

enter image description here

1 Answer 1

1

commands you add with on background layer are accumulated and put all together in one picture. This means that you need additional scoping environments:

\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}

enter image description here

2
  • Thanks! I tried an additional outer scope, not an inner one.
    – Dirk
    Jan 14, 2021 at 9:27
  • And I merged the "on background layers".
    – Dirk
    Jan 14, 2021 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .