2

I have the following code to show union of two sets. But the problem is that the intersection of the two sets in the diagram below has been colored twice instead of just once. As we can see in the below screenshot the intersecting part is colored twice but I want it to be colored only once just like the rest of the union part. Here is the code to reproduce the problem:

\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \begin{scope} [fill opacity = .3] \draw[fill=gray, draw = black] (3.5,2.5) circle (1.5); \draw[fill=gray, draw = black] (6,2.5) circle (2); \end{scope} \end{tikzpicture} \end{document} 

Here is the screenshot for reference. enter image description here

2
  • Is there something behind the circles? There's no need to use opacity if you don't need it. You can do just as well \draw[draw=black, fill=gray!30] for the same effect. Drawing it as one path is still a good idea, as you can use even odd filling rule to not fill in the middle area. Commented Mar 26 at 20:37
  • @Qrrbrbirlbel I see. You can/should add this as an answer as this will help beginners and future readers like me in latex. Commented Mar 27 at 1:42

1 Answer 1

4

In your simple example, you could draw both circles in one go:

\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \begin{scope}[opacity=.3] \draw[fill=gray, draw = black] (3.5,2.5) circle (1.5) (6,2.5) circle (2); \end{scope} \end{tikzpicture} \end{document} 

enter image description here

More generally, you could use a blend group:

\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \begin{scope}[opacity=.3,blend group=overlay] \draw[fill=gray, draw = black] (3.5,2.5) circle (1.5); \draw[fill=gray, draw = black] (6,2.5) circle (2); \end{scope} \end{tikzpicture} \end{document} 

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.