1

Referring to the post:

How to draw Venn diagrams (especially: complements) in LaTeX

using the suggested code:

\documentclass{letter}
\usepackage{tikz}
\def\firstcircle{(90:1.75cm) circle (2.5cm)}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
  \begin{tikzpicture}
    \begin{scope}
  \clip \secondcircle;
  \fill[cyan] \thirdcircle;
    \end{scope}
    \begin{scope}
  \clip \firstcircle;
  \fill[cyan] \thirdcircle;
    \end{scope}
    \draw \firstcircle node[text=black,above] {$A$};
    \draw \secondcircle node [text=black,below left] {$B$};
    \draw \thirdcircle node [text=black,below right] {$C$};
  \end{tikzpicture}
\end{document}

I could achieve the first Venn digram appears in the post. However, I would like to add a bigger box which includes all the other ones, and add a name to it (say "H"). Such an option appears as a third suggestion in the same post, here is the code:

\begin{tikzpicture}[fill=gray]
% left hand
\scope
\clip (-2,-2) rectangle (2,2)
      (1,0) circle (1);
\fill (0,0) circle (1);
\endscope
% right hand
\scope
\clip (-2,-2) rectangle (2,2)
      (0,0) circle (1);
\fill (1,0) circle (1);
\endscope
% outline
\draw (0,0) circle (1) (0,1)  node [text=black,above] {$A$}
      (1,0) circle (1) (1,1)  node [text=black,above] {$B$}
      (-2,-2) rectangle (3,2) node [text=black,above] {$H$};
\end{tikzpicture}

but I could not combine the codes in the right way to get the wished result.

Thank you for any help!

1 Answers1

0

Something like this?

\documentclass[tikz,border=3mm]{standalone}
\def\firstcircle{(90:1.75cm) circle (2.5cm)}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\begin{tikzpicture}
 \begin{scope}
  \clip \secondcircle;
  \fill[cyan] \thirdcircle;
 \end{scope}
 \begin{scope}
  \clip \firstcircle;
  \fill[cyan] \thirdcircle;
 \end{scope}
 \draw \firstcircle node[text=black,above] {$A$};
 \draw \secondcircle node [text=black,below left] {$B$};
 \draw \thirdcircle node [text=black,below right] {$C$};
 \draw ([xshift=-1em,yshift=-1em]current bounding box.south west)
   rectangle
    ([xshift=1em,yshift=1em]current bounding box.north east);
 \path (current bounding box.north) node[above]{$H$};
\end{tikzpicture}
\end{document}

enter image description here

You could also use the venndiagram package.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{venndiagram}
\usetikzlibrary{backgrounds}
\makeatletter% https://tex.stackexchange.com/a/499947
\tikzset{interior of/.style={insert path={
 (\csname @venn@#1x\endcsname,\csname @venn@#1y\endcsname) circle[radius=\@venn@radius-\pgflinewidth/2]}},
 contour of/.style={insert path={
 (\csname @venn@#1x\endcsname,\csname @venn@#1y\endcsname)
 circle[radius=\@venn@radius]}},
 midpoint of/.style={insert path={
 (\csname @venn@#1x\endcsname,\csname @venn@#1y\endcsname)
 }}}
\makeatother 
\begin{document}
\begin{venndiagram3sets}[labelA=$A$,labelB=$B$,labelC=$C$]
\setpostvennhook{
\begin{scope}[on background layer]
 \clip[interior of=C];
 \fill[cyan,interior of=A,interior of=B];
\end{scope}
\path (current bounding box.north) node[above]{$H$};}
\end{venndiagram3sets}
\end{document}

enter image description here

Or with the unofficial library venn.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{venn}
\begin{document}
\begin{tikzpicture}
\begin{scope}[Venn diagram={offset angle=-60,style={fill=cyan}}] 
\clip[venn/set=C];
\Venn{AuB}
\end{scope}
\path (current bounding box.north) node[above]{$H$};
\end{tikzpicture}
\end{document}

enter image description here