1

Getting back to my usually questions, I am looking to have fun with this question and pursue ideas how to write a better program for the tikz diagram(Venn Diagram) below. Marmot told me not to nest tikzpictures so this is one solution to do so. I am interested in other ideas. Modify as you wish!

\documentclass{article}
%\usepackage{geometry}
\usepackage{tikz}

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\newcommand{\A}{\mathbf{A}}
\newcommand{\B}{\mathbf{B}}
\newcommand{\C}{\mathbf{C}}
\newcommand{\x}{\mathbf{x}}

\begin{document}

\def\thirdcircle{(0,0) ellipse (1.5cm and .5cm)}     %%%%%% A
\def\secondcircle{(0,0) ellipse (2.25cm and .75cm)}  %%%%%% B
\def\firstcircle{(0,0) ellipse (3cm and 1cm)}        %%%%%% C
\def\Extracircle{(2,0) ellipse (1.1cm and 2cm)}      %%%%%% Extra Set 
                                                        C in part(c)

\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}}


\begin{center}
\begin{minipage}{.45\textwidth}
\begin{tikzpicture}
  \begin{scope} 
        \clip \Extracircle;
            \fill[filled] \thirdcircle;
        \end{scope} 
 \draw[outline] \firstcircle node[right=2.25cm] {$\A$};
     \draw[outline] \thirdcircle node [] {$\B$};
   \draw[fill] (0:1) circle (1pt) node[right=1pt] {\scriptsize $\x$};   
 \draw[outline] \Extracircle node[above=1cm] {$\C$};
    \node at (0,-2) [below] {$\mathbf{B \cap C}$};
    \node at (4,-2) [below] {$\mathbf{\subset}$};
 \end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tikzpicture}
\begin{scope} 
        \clip \Extracircle;
            \fill[filled] \firstcircle;
        \end{scope} 
 \draw[outline] \firstcircle node[right=2.25cm] {$\A$};
     \draw[outline] \thirdcircle node [] {$\B$};
   \draw[fill] (0:1) circle (1pt) node[right=1pt] {\scriptsize $\x$};   
 \draw[outline] \Extracircle node[above=1cm] {$\C$};
\node at (0,-2) [below] {$\mathbf{A \cap C}$};
\end{tikzpicture}
\end{minipage}
\end{center}

\end{document}

This outputs:

enter image description here

  • This does not seem to nest tikzpictures. What precisely is your question? – user121799 Jan 27 at 20:20
  • Other programs which achieve similar results. This uses minipage. Perhaps there is another method to format the tikzpictures. My original programs nested the two tikzpictures. – MathScholar Jan 27 at 20:25
  • 1
    @MathScholar For the clipping, have you tried using the odd-even-rule from tikz? Often times it's much simpler than normal clipping. – Dave Jan 27 at 20:26
  • @Dave yes I have used but I don't completely understand it. Please post what you have in mind. The purpose of this question is to improve my programming skills. I did use the odd-even rule in more complicated set theory questions in higher algebra – MathScholar Jan 27 at 20:28
5

Let me start by saying that if you are fine with the outcome and you do not have any problems with it, you may just leave it as is and not try to "improve" it. Since you ask here, here come a few suggestions (focusing on the TikZ part and ignoring the page geometry issues, which can be addressed more elegantly by really using the geometry package.)

This is some code in which some of the things got changed.

  1. Instead of minipages, here the two parts are put in scopes (with local bounding boxes). This can help when it comes to adjusting the distance, and in particular now the figure is really centered. In your example, the minipages but not necessarily the figure was centered. (I personally would probably use \centering here.)
  2. Instead of storing the various ellipses in macros, they get stored in TikZ styles. (This is not necessarily "better" but may be considered TikZier. ;-)
  3. I also added some application of the even odd rule, which got mentioned by Dave in the mean time.

\documentclass{article}
%\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{patterns}
\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\newcommand{\A}{\mathbf{A}}
\newcommand{\B}{\mathbf{B}}
\newcommand{\C}{\mathbf{C}}
\newcommand{\x}{\mathbf{x}}

\begin{document}

C in part(c)

\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}}


\begin{center}
\begin{tikzpicture}[standard ellipse/.style={insert path={(0,0) ellipse (#1*1.5cm and #1*.5cm)}},
standard ellipse/.default=1,
extra circle/.style={insert path={(2,0) ellipse (1.1cm and 2cm)}}]
 \begin{scope}[local bounding box=left]
  \coordinate (O) at (0,0);
  \begin{scope} 
   \clip[extra circle];
   \fill[filled,standard ellipse];
  \end{scope} 
  \draw[outline,standard ellipse=2] node[right=2.25cm] {$\A$};
  \draw[outline,standard ellipse] node [] {$\B$};
  \draw[fill] (0:1) circle (1pt) node[right=1pt,font=\scriptsize] {$\x$};   
  \draw[outline,extra circle] node[above=1cm] {$\C$};
  \node at (0,-2) [below] {$\mathbf{B \cap C}$};
  \node at (4,-2) [below] {$\mathbf{\subset}$};
 \end{scope}
 \begin{scope}[local bounding box=right,shift={([xshift=3cm]left.east|-O)}]
  \begin{scope} 
   \clip[extra circle];
   \fill[filled,standard ellipse=2];
   \path[pattern=north east lines,even odd rule,standard ellipse=2,standard
   ellipse=1];
  \end{scope} 
  \draw[outline,standard ellipse=2] node[right=2.25cm] {$\A$};
  \draw[outline,standard ellipse] node [] {$\B$};
  \draw[fill] (0:1) circle (1pt) node[right=1pt,font=\scriptsize] {$\x$};   
  \draw[outline,extra circle] node[above=1cm] {$\C$};
  \node at (0,-2) [below] {$\mathbf{A \cap C}$};
 \end{scope} 
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

  • I think the idea you wrote here : tex.stackexchange.com/questions/455999/similar-triangles would work as well. I have not worked out the details but it could be applied to the diagram above as well! Thanks Marmot! – MathScholar Jan 28 at 1:38
  • 1
    @MathScholar I agree. Yet here the reason why I slightly preferred insert path is that one does not have to modify too much of your original code, i.e. \draw[outline,extra circle] node[above=1cm] {$\C$}; works because one is still in the same path. pics are more useful if you want to repeat a drawing consisting of several paths, and if one wants to rotate or rescale them. But there is no strict boundary. – user121799 Jan 28 at 1:57

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.