3

I would like the intersection of sets P and Q to be white as in the attached figure.

enter image description here

My command is as follows:

\documentclass[10pt, a4paper, serif, xcolor = {divpsnames, svgnames}]{beamer}
\usepackage{amsmath, mathtools, mathrsfs, amstext, xfrac}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
    \begin{frame}
        \frametitle{}{}
           \begin{figure}
               \centering
                   \begin{tikzpicture}
                       \begin{scope}[fill opacity = .5, text opacity = 1]
            \draw[fill = Green!70!white, even odd rule] (5, -2) rectangle (-3.5, 2) (0:2cm) circle [radius = 1];
            \draw[fill = Green!70!white, draw = black, even odd rule] (0, 0) circle [radius = 1.5];
            \draw[fill = white, draw = black, even odd rule] (0:2cm) circle [radius = 1];
    
                \node at (2, 1.3) (Q) {$Q$};
                \node at (0, 1.7) (P) {$P$};
                \node at (4.7, 1.7) (E) {$E$};
                       \end{scope}
                   \end{tikzpicture}
                       \caption{Representação de $P - Q$.}
                           \label{fig9}
        \end{figure}

    \end{frame}
\end{document}

enter image description here

Thanks in advance!

1
  • 1
    Use for instance \draw[fill = white, draw = black, even odd rule] (0, 0) circle [radius = 1.5]; for the second \draw call (the third one may be commented out).
    – frougon
    Mar 1, 2020 at 14:48

2 Answers 2

3

Simple way with no magic that fills the non-substracted part of the left circle (set) in darker green than the beckground, as you appear to desire:

\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\fill[Green!35!white, even odd rule]
  (5,-2) rectangle (-3.5,2)
  (0:2cm) circle[radius = 1];
\fill[Green!60!white] (0,0) circle[radius=1.5];
\filldraw[fill=white, draw=black] (0:2cm) circle [radius=1];
\draw[black] (0, 0) circle [radius=1.5];

\node at (2, 1.3) (Q) {$Q$};
\node at (0, 1.7) (P) {$P$};
\node at (4.7, 1.7) (E) {$E$};
\end{tikzpicture}

\end{document}

enter image description here

Here is another way using clipping to fill the intersection in white:

\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\fill[Green!35!white, even odd rule]
  (5,-2) rectangle (-3.5,2)
  (0:2cm) circle [radius=1];
\filldraw[fill=Green!60!white, draw=black] (0,0) circle[radius=1.5];

\begin{scope}
  \clip (0:2cm) circle[radius=1];
  \filldraw[fill=white, draw=black] (0,0) circle[radius=1.5];
\end{scope}

\draw[black] (0:2cm) circle [radius=1];
\node at (2, 1.3) (Q) {$Q$};
\node at (0, 1.7) (P) {$P$};
\node at (4.7, 1.7) (E) {$E$};
\end{tikzpicture}

\end{document}

With this one, you can simply edit the fill=white to fill the intersection of both sets with the color of your choice.

2

This is just for fun, and to provide you with a couple of standard tricks that are collected from various posts (and linked, of course). There is the possibility to have an even odd clip and to reuse paths. Unfortunately the "official" version that got implemented via use path does not always do what we want so there is also the reuse path, which allows us to recycle a path that has been previously stored in a macro via save path. In general, this tool box can be used to draw any Venn diagram rather conveniently, and these tools have also been collected in the experimental TikZ library venn, which I am however not using here. With the even odd clip we can fill everything but the Q circle.

\documentclass[10pt, a4paper, serif, xcolor = {divpsnames, svgnames}]{beamer}
\usepackage{tikz}
% based on
% https://tex.stackexchange.com/a/38995/121799
% https://tex.stackexchange.com/a/76216
% https://tex.stackexchange.com/a/59168/194703
% https://tex.stackexchange.com/q/448920/194703
\makeatletter 
\tikzset{
  reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}},
  even odd clip/.code={\pgfseteorule}}
\makeatother
\usepackage{amssymb}
\begin{document}
\begin{frame}[t]
\frametitle{Another Venn diagram}
\begin{figure}
 \centering
 \begin{tikzpicture}
  \begin{scope}[fill opacity = .5]
   \draw[save path=\pathE]  (-3.5, -2) rectangle (5, 2);
   \draw[save path=\pathQ]  (0, 0) circle [radius = 1.5];
   \draw[save path=\pathP] (0:2cm) circle [radius = 1];
   \clip[even odd clip,reuse path=\pathP]  (-3.5, -2) -|(5, 2) -| cycle;
   \fill[Green!70!white,use path=\pathE]; 
   \fill[Green!70!white,use path=\pathQ];
  \end{scope}
  \node at (2, 1.3) (Q) {$Q$};
  \node at (0, 1.7) (P) {$P$};
  \path (5, 2)  node[below left](E) {$E$};
 \end{tikzpicture}
 \caption{Representa\c{c}\~ao de $P - Q$.}
 \label{fig9}
\end{figure}
\end{frame}
\end{document}

enter image description here

You must log in to answer this question.

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