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

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

  • Thanks! I tried an additional outer scope, not an inner one. – Dirk 2 days ago
  • And I merged the "on background layers". – Dirk 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.