3

I know there are many threads on Venn diagrams with tikz, however I could not find this specific case. I would like to fill the complement of the disjunction of p and q. Graphically, this would be everything in the rectangle except for the two circles (which should be white). I have a working example, where I first fill the rectangle and the conjunction of p and q, and then fill of white the conjunction. However, this seems unnecessarily artificial, so I feel there probably is a better way of doing it. (It's done implicitly here but my tikz is not very good so I am not understanding clearly. Moreover it looks like overkill for what I need)

My code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}

\def\bigrectangle{(-2,-2) rectangle (3,2)}
\def\firstcircle{(0,0) circle (1)}
\def\secondcircle{(1,0) circle (1)}

% fill rectangle and conjunction
\scope
    \clip \firstcircle \secondcircle \bigrectangle;
    \fill[blue] \bigrectangle;
\endscope

% fill conjunction white
\scope
    \clip \secondcircle;
    \fill[white] \firstcircle;
\endscope

% outline
\draw \firstcircle (0,1) node [text=black,above] {$p$}
      \secondcircle (1,1) node [text=black,above] {$q$}
      \bigrectangle node [text=black,above] {$U$};

\end{tikzpicture}

\end{document}

This is the result:

Looks right but code is weird

1
  • Why are you using the scope blocks at all? You can get the same output with just \fill[blue!20] \bigrectangle; \fill[white] \firstcircle \secondcircle;
    – Thruston
    May 15, 2017 at 11:34

1 Answer 1

2

enter image description here

\documentclass{article}

\usepackage{venndiagram}


\begin{document}
\begin{venndiagram2sets}
\fillNotAorB
\end{venndiagram2sets}
\end{document}

You can change colors, labels, etcetera, easily as described in the package documentation.

1
  • 1
    While this works for 2 sets, it does not seem to work for 3 sets, does anyone know another method except for \fillNotAorBorC ?
    – PolkaDot
    Aug 3, 2020 at 10:23

You must log in to answer this question.

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