0

I am wondering about package or a simple way to draw Venn diagrams. I need to draw the following examples:

enter image description here

and as you can see my hand drawing skills are not up to the task :)

I have found the package named venndiagram and it seem to be able to help me with 4 and 5 but not the rest. I mean sometimes I want to only show one of the circles, sometimes none of the circles, sometimes overlapping, sometimes not and so on. I also found a package named just venn but it seems to have a not so satisfactory documentation so I don't know if it could help me or not. To me this seems like something people would do from time to time so I was hoping someone could suggest something else?

2
  • Seems there are no easy ways around this except handcrafting in tikz. Is that cause for closing?
    – jonalv
    Jun 30, 2020 at 12:04
  • 2
    I think this question is sufficiently different, because it asks about using the venndiagram package instead of using only tikz, so I voted for reopening.
    – Marijn
    Jul 2, 2020 at 10:16

1 Answer 1

1

You can add some options to the original code using draw and fill parameters for the circles and the rectangle. Modifying the code on the fly can be done using the xpatch package, similar to Venn diagram outlines.

Then you can set the commands used in those parameters to values that correspond to the diagram that you want to draw. Using draw=none and an empty label a circle can be removed from the diagram, and fill=white makes a circle visible if the rectangle is filled with fill=lightgray. To resume drawing 'normal' diagrams you need to reset the macros to the default values.

Note that #6 does not need any modifications, this can be done by setting the provided key overlap to a negative value.

MWE:

\documentclass{article}
\usepackage{venndiagram}
\usepackage{xpatch}

\def\framefill{none}
\def\afill{none}
\def\bfill{none}
\def\adraw{black}
\def\bdraw{black}

\makeatletter
% patch drawing of A and B
\xpatchcmd{\endvenndiagram2sets}
{%
\draw (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
\draw (\@venn@Bx,\@venn@By) circle (\@venn@radius);
}
{
\draw [draw=\adraw, fill=\afill] (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
\draw [draw=\bdraw, fill=\bfill] (\@venn@Bx,\@venn@By) circle (\@venn@radius);
}
{\typeout{patch ok}}{\typeout{patch failed}}
% patch frame
\xpatchcmd{\endvenndiagram2sets}
{\draw (venn bottom left) rectangle (\@venn@w,\@venn@h);}
{\draw [fill=\framefill] (venn bottom left) rectangle (\@venn@w,\@venn@h);}
{\typeout{patch ok}}{\typeout{patch failed}}
\makeatother

\begin{document}
\begin{venndiagram2sets}
\fillA \fillB
\end{venndiagram2sets}
\begin{venndiagram2sets}
\fillACapB
\end{venndiagram2sets}

\begin{venndiagram2sets}[overlap=-0.75cm]
\fillA \fillB
\end{venndiagram2sets}

\def\bdraw{none}
\begin{venndiagram2sets}[labelB={}]
\fillA
\end{venndiagram2sets}
\def\framefill{lightgray}
\def\afill{white}
\begin{venndiagram2sets}[labelB={$A^c$}]
\end{venndiagram2sets}

\def\afill{none}
\def\adraw{none}
\begin{venndiagram2sets}[labelA={},labelB={}]
\end{venndiagram2sets}

\end{document}

Result:

enter image description here

You must log in to answer this question.

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