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

  • 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 '17 at 11:34
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.

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.