4

I have not used the venndiagram package before. I have tried to read the manual, but could not find an answer to how to make the universal set box fit for any number of elements.

Here is what I have so far:

    \documentclass{book}

 \usepackage{newfile}
 \usepackage{amsmath}
 \usepackage{xifthen}
 \usepackage{enumitem}
 \usepackage{multicol}
 \usepackage{lipsum}
 \usepackage{multirow}
 \usepackage{blindtext}
 \usepackage{amsfonts}
 \usepackage{booktabs}
 \usepackage{longtable}
 \usepackage{makecell}
 \usepackage{cancel}
 \usepackage{tikz}
 \usetikzlibrary{tikzmark,shapes.misc}
 \usepackage{venndiagram}
 \usetikzlibrary{fit}
 \usepackage[left=2.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}
\usepackage{cellspace}
%------------------------------------


%-----------------------------------

\renewcommand\theadfont{\bfseries}




\usepackage{verbatim}
%\usepackage[active,tightpage]{preview}
%\PreviewEnvironment{tikzpicture}
%\setlength\PreviewBorder{5pt}%

\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}

\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}

 \tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
    outline/.style={draw=circle edge, thick}}

 \setlength{\parskip}{5mm}


\begin{document}

 \chapter{Sets and Venn Diagrams}

     \section{Sets}

  A set is a specific group of numbers or items from a list.          The items in this set   (the list list), are called Elements.\\
Sets can be written in a few different ways - eg the set $A$      can be  written as,  $A=\{1,8,27,64\}$, $A=\{Cube \: numbers    <100\}$ and  $A=\{x:x \:is \:a \:cube \:number   \:less \:than    \:100\}$

     \section{Set Notiation}

 If we take the natural numbers, $\mathbb{N} \leq10$ 

  \begin{tabular}{|c|c|c|c|}
  \hline
   Sybmol             & Name                       & Example                                                                  & Explanation\\
  \hline
 $\{\}$                  & Set                           &   \thead{$A=\{1,3\}$ \\ $B=\{2,3,9\}$ \\ $C=\{3,9\}$} &  Collection   of objects or items\\
 \hline
 $\cap$                & intersect                   & $A \cap    B = \{3\}$                                                  &  3    belongs to both sets $A$ and $B$ \\
 \hline
 $\cup$                & Union                        & $A \cup    B = \{1,2,3,9\}$                                         & The       elements belong to both $A$ and $B$ \\
 \hline
 $\xi$                    & The universal set     & $\xi=\ {4,5,6,7,8,10\}$                                             & All     the elements not in the sets  \\
 \hline
 $\subset$            & Proper subset          & \thead{$\{1\}    \cup A$  \\ $C \cup B$}                     & A set is contained in    another set \\
 \hline
 $\subseteq$        &Subest                      & $\thead{B   \subseteq A \\ \{1,3\}}$                          &  A set that is     contained in or equal to another set\\
 \hline
 $\not \subseteq$ & Not a proper subset & $\{1,3\}$                                                                  & A set the is not contained in another set \\
 \hline
 $\supset$            & Superset                  & $B  \supset C$                                                     &  Set $B$   includes set $C$\\
 \hline
 $\epsilon$           & is a member of         & $3 \epsilon  A$                                                     & $3$ is in  the set $A$\\
 \hline
 $\not\epsilon$     & is not a member of   & $4 \not\epsilon A $                                                  & $4$ is not in   the set $A $\\
 \hline

 \end{tabular}


  %--------------------------Problem code is here------------------%

 my attempt
 \begin{venndiagram3sets}[labelOnlyA={1},labelOnlyB=  {2},labelOnlyC={}, labelOnlyAB={},labelOnlyAC={},labelOnlyBC=  {9},labelABC={3}, labelNotABC={4,5,6,7,8,10}]
     \end{venndiagram3sets} %My Attempt

 %------------------------------------%

 First suggestion
 \begin{venndiagram3sets}[
   labelOnlyA={1},
   labelOnlyB={2},
   labelOnlyC={},
   labelOnlyAB= {},
   labelOnlyAC={},
   labelOnlyBC={9},
   labelABC={3},
   labelNotABC={4,5,6,7,8,10},
    showframe=false,
 ]
  \setpostvennhook{
   \node[below left] at (venn top right) {\(\mathcal{E}\)};
   \node[fit=(venn top right) (venn bottom left)   (labelNotABC),draw] {};
 }
 \end{venndiagram3sets} % second attempt

  %--------------------------------------------%
  Second suggestion
  \fbox{\begin{venndiagram3sets}[showframe=false,labelOnlyA= {1},labelOnlyB={2},labelOnlyC={}, labelOnlyAB= {},labelOnlyAC= {},labelOnlyBC={9},labelABC={3}, labelNotABC={$\xi$ \ {4,5,6,7,8,10\}}]
     \end{venndiagram3sets}} %third attempt

  %-----------And ends here----------------------------------%

  %Diagrams

     \section{diagrams}

     % Definition of circles

  \begin{tabular}{cc}
  % Set A and B
 \begin{tikzpicture}
     \begin{scope}
          \clip \firstcircle;
          \fill[filled] \secondcircle;
     \end{scope}
     \draw[outline] \firstcircle node {$A$};
     \draw[outline] \secondcircle node {$B$};
     \node[anchor=south] at (current bounding box.north) {$A \cap B$};
 \end{tikzpicture}

 &
  %Set A or B but not (A and B) also known a A xor B
  \begin{tikzpicture}
     \draw[filled, even odd rule] \firstcircle node {$A$}
                                  \secondcircle node{$B$};
     \node[anchor=south] at (current bounding box.north)  {$\overline{A \cap B}$};
  \end{tikzpicture}

  % Set A or B
 \begin{tikzpicture}
      \draw[filled] \firstcircle node {$A$}
                   \secondcircle node {$B$};
      \node[anchor=south] at (current bounding box.north) {$A \cup B$};
 \end{tikzpicture}\\

 % Set A but not B
 \begin{tikzpicture}
     \begin{scope}
         \clip \firstcircle;
         \draw[filled, even odd rule] \firstcircle node {$A$}
                                      \secondcircle;
     \end{scope}
     \draw[outline] \firstcircle
                    \secondcircle node {$B$};
     \node[anchor=south] at (current bounding box.north) {$A - B$};
     \end{tikzpicture}

 &
 % Set B but not A
 \begin{tikzpicture}
     \begin{scope}
         \clip \secondcircle;
         \draw[filled, even odd rule] \firstcircle
                                      \secondcircle node {$B$};
     \end{scope}
     \draw[outline] \firstcircle node {$A$}
                    \secondcircle;
     \node[anchor=south] at (current bounding box.north) {$B -  A$};
 \end{tikzpicture}\\

 \end{tabular}

 \end{document}

I have edited this to provide all the code for my page incase anything is causing my problems. sorry for the long code.enter image description here

3
  • Just to clarify: do you want the square to be larger so that $\xi$ \{4,5,6,7,8,10\} is inside the square? Aug 8, 2022 at 16:41
  • Yes, but automatically resize depending on the number of elements, if that is possible.
    – Paul A
    Aug 8, 2022 at 16:48
  • You should maybe tidy the code of your MWE. You load tikz twice and it is unclear to me why you define some circles which you don't use later. Aug 8, 2022 at 16:52

3 Answers 3

4

I am not sure what you want to achieve, but I think you want to place the label for the universal set at a place where it does not intersect with the surrounding box.

This answer explains how you can use the macro \setpostvennhook to customize the position of the labels. The manual of the package further adds that there are coordinates in all four corners of the venn diagram, which you can use to align the labels. You can also use the options vgap or hgap to increase the margin between the circles and the outer box.

Of course, if the contents of the label is too long, it will eventually "crash" into the right border of the surrounding box ...

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{venndiagram}

\begin{document}

\begin{venndiagram3sets}[labelOnlyA={1}, labelOnlyB={2}, labelOnlyC={}, labelOnlyAB= {}, labelOnlyAC={}, labelOnlyBC={9}, labelABC={3}, vgap=.75cm]

    \setpostvennhook{
        \node[anchor=south west] at (venn bottom left) {$\xi$ \{4,5,6,7,8,10\}};
    }

\end{venndiagram3sets}

\end{document}   

enter image description here

4

You can use the \setpostvennhook to insert arbitrary TikZ code to be drawn after the venn diagram is constructed. Since the default size of the frame doesn't take into account the labels, it can be redrawn here taking that into account. Specifically, using the fit library then a node can be drawn that is guaranteed to encompass the diagram and the non-ABC label. Note that you need the option showframe=false to avoid drawing the original universal set frame.

I've also make a couple of other changes:

  1. The elements not in the sets A,B,C shouldn't be enclosed in braces. Technically, writing \{4,5,6,7,8,10\} indicates that the outer region contains one element which is the set containing 4,5,6,7,8,10. I presume that what you want to indicate is that the outer region itself contains those numbers.
  2. To avoid the symbol for the universal set getting confused with the elements, I've used the \setpostvennhook to place its symbol in the top right corner (which, I think, is a more standard place for it to be). I've also used \mathcal{E} rather than \xi.
\documentclass{book}
%\url{https://tex.stackexchange.com/q/653355/86}
\usepackage{tikz}
\usepackage{venndiagram}
\usetikzlibrary{fit}


\usepackage[left=2.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}

\begin{document}
\begin{venndiagram3sets}[
  labelOnlyA={1},
  labelOnlyB={2},
  labelOnlyC={},
  labelOnlyAB= {},
  labelOnlyAC={},
  labelOnlyBC={9},
  labelABC={3},
  labelNotABC={4,5,6,7,8,10},
  showframe=false,
]
\setpostvennhook{
  \node[below left] at (venn top right) {\(\mathcal{E}\)};
  \node[fit=(venn top right) (venn bottom left) (labelNotABC),draw] {};
}
\end{venndiagram3sets}
\end{document}

Venn diagram with universal set adjusted to fit contents

3

Instead of letting the venndiagram package draw the rectangle, you could wrap it into an \fbox

\documentclass{book}

\usepackage{makecell}
\usepackage{tikz}
\usepackage{venndiagram}

\renewcommand\theadfont{\bfseries}

\usepackage{cellspace}

\usepackage{tikz}
\usepackage{verbatim}

\usepackage[left=2.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}

\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}

\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}

\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
     outline/.style={draw=circle edge, thick}}

\setlength{\parskip}{5mm}


\begin{document}
\fbox{\begin{venndiagram3sets}[showframe=false,labelOnlyA={1},labelOnlyB={2},labelOnlyC={}, labelOnlyAB= {},labelOnlyAC={},labelOnlyBC={9},labelABC={3}, labelNotABC={$\xi$ \{4,5,6,7,8,10\}}]
    \end{venndiagram3sets}}
    \end{document}   

enter image description here

13
  • Thanks @samcarter_is_at_topanswers.xyz but when I run this cadet does give me the right sized box but also gives me the original box, am I running it on LaTex should I be using something different I have tried ExLaTex and other but nothing seems to work.
    – Paul A
    Aug 8, 2022 at 17:05
  • @PaulA Did you add the showframe=false to switch off the original box? Aug 8, 2022 at 18:23
  • Hi @samcarter_is_at_topanswers.xyz I turned show frame to false, in fact I have tried to just copy and paste your code and it still will not work. I think I need to go back to basics as everything I have read suggested the same as you.
    – Paul A
    Aug 9, 2022 at 9:13
  • @PaulA Maybe version of the venndiagram package is too old? I think the option was added sometime in 2017 or 2018. Aug 9, 2022 at 9:34
  • 1
    @PaulA You're welcome! Have fun with all the very important new packages in texlive 2022 like ctan.org/pkg/sillypage :) (during the year, one can simply update texlive to get all the new package versions, but once a year one needs to install the new version) Aug 9, 2022 at 19:47

You must log in to answer this question.

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