0

Please help me, I am typing a book

enter image description here

\documentclass[x11names]{article}
% Set operations illustrated with Venn diagrams
% Author: Uwe Ziegenhagen
% This is an expanded version of an example provided by T. Tantau

\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>



\begin{document}

% Definition of circles
\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}




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


\end{document}
  • 5
    Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. – Christopher Apr 2 '15 at 17:34
  • 1
    You've added some code now, but it's not entirely clear how that code relates to your question (you also do not say anything about it). There's no clear relation between the picture you want and the picture your code draws. – Sverre Apr 2 '15 at 17:45
  • 3
    You might like the venn diagram package. Nice simple syntax, built on TikZ. – Thruston Apr 2 '15 at 17:51
  • @Thruston Nice package. Perhaps you should post that as an answer. Though technically the package does load TikZ. – A.Ellett Apr 2 '15 at 17:55
  • @A.Ellett, well I'm not sure what the OP really wants - if the apparently random numbers really need to be spread about like that then a more free-form drawing might be better. – Thruston Apr 2 '15 at 18:04
5

As usual, Google is your friend. Take a look at this canonical example which comes out first in my search. The main trick there is using polar coordinates to spread the circles.

If you do not like polar coordinates, add Cartesian coordinates which should make it more convenient to place the numbers and other decorations in an approximation of their "appropriate" positions.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds}
\begin{document}
  \def\firstcircle{(135:1.2) circle (2)}
  \def\secondcircle{(45:1.2) circle (2)}
  \def\thirdcircle{(-90:1.2) circle (2)}
  \begin{tikzpicture}
    \tikzset{help lines/.style={color=blue!20}}
    \draw[thin,help lines] (-4.5,-4.5) grid (4.5,4.5);
    \draw[ultra thin,step=.5,help lines] (-4.5,-4.5) grid (4.5,4.5);
    \draw[thick] (-4.5,0) -- (4.5,0); % x acis
    \draw[thick] (0,-4) -- (0,4.5); % y acis
    \foreach \x in {-4,...,4} { \draw [thick] (\x,0) -- (\x,-0.2); }
    \foreach \y in {-4,...,4} { \draw [thick] (0,\y) -- (-0.2,\y); }
    \foreach \x in {-4,-3,...,4} { \node [anchor=north,text=blue] at (\x,-0.2) {\x}; }
    \foreach \y in {-4,-3,...,4} { \node [anchor=east,text=blue] at (-0.2,\y) {\y}; }
    \foreach \x in {-3.5,-3,...,3.5} {\draw [thin,help lines] (\x,0) -- (\x,-0.1);}
    \foreach \y in {-3.5,-3,...,3.5} {\draw [thin,help lines] (0,\y) -- (-0.1,\y);}
    \draw \firstcircle;
    \draw \secondcircle;
    \draw \thirdcircle;
    \node at (0,0) {2};
    \node at (0,1.5) {9};
    \node at (1,-0.5) {4};
    \node at (-1,-0.5) {5};
    \node at (-2,1.5) {10};
    \node at (2,1.5) {6};
    \node at (2,-3) {$\mathbf L$};
    \node at (-2,3) {$\mathbf M$};
    \node at (2,3) {$\mathbf N$};
    \node at (3,-1) {11};
    \node at (-3,-1) {23};
    \node at (-3,-3) {13};
    \node at (3,3) {13};
    \node at (-3,3) {$\mathbf U$};
  \end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • 3
    This should be a comment, not an answer. – Sverre Apr 2 '15 at 17:48
  • You are probably right; I guess the question should have been answered with this link http://lmgtfy.com/?q=tikz+venn. But, others may find a more detailed answer useful. – Yossi Gil Apr 2 '15 at 18:57
3
\documentclass[border=2mm,tikz]{standalone}
\usepackage{bm}

\begin{document}

    \begin{tikzpicture}[thick]
        \draw (2.7,-2.54) rectangle (-1.5,1.5) node[below right] {$\bm{U}$};
        \draw (0,0) circle (1) node[above,shift={(0,1)}] {$\bm{M}$};
        \draw (1.2,0) circle (1) node[above,shift={(0,1)}] {$\bm{N}$};
        \draw (.6,-1.04) circle (1) node[shift={(1.1,-.6)}] {$\bm{L}$};

        \node at (.6,-.4) {2};
        \node at (1.2,-.7) {4};
        \node at (0,-.7) {5};
        \node at (1.4,.2) {6};
        \node at (.6,.3) {9};
        \node at (-.2,.2) {10};
        \node at (2.2,-1.2) {11};
        \node at (-1,-2.2) {12};
        \node at (2.4,1.2) {13};
        \node at (.3,-1.5) {16};
        \node at (1,-1.4) {21};
        \node at (-1.2,-1.5) {23};
\end{tikzpicture}

\end{document}

enter image description here

| improve this answer | |
2

The venndiagram package suggested by Thruston is very good for drawing these diagrams and I'm sure there are other ways to do it. That being said, if you can't wrap your head round moving or removing labels in that package or if you're a TikZ newbie you can always take to manual approach (which can be easier to understand as a start point).

The basic idea behind this code is the three circles and then placing nodes between them for some of the labels with xshift and yshift being used when necessary to adjust the positions.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{backgrounds,calc}


\begin{document}

\begin{tikzpicture}[venncircle/.style={draw, circle, minimum size=15em, align=center}, node distance=12.5em, framed] 
        \node[venncircle] (circle1) {10};    
        \node[venncircle, right of=circle1] (circle2) {6};
        \node (MN) at ($(circle1)!0.5!(circle2)$){9};
        \node[venncircle, below of=MN, yshift=3em] (circle3) {}; %yshift value by pythagoras
        \node (ML)  at ($(circle1)!0.5!(circle3)$){5};  
        \node (NL)  at ($(circle2)!0.5!(circle3)$){4};   
        \node (MNL)  at ($(MN)!0.3!(circle3)$){2};
        \node (Lleft) [below of=ML, yshift=5em] {16};
        \node (Lright) [below of=NL, yshift=5em] {21};
        \node (outbotrightnum) [right of=circle3, yshift=1.5em, xshift=-2em] {11};
        \node (outtoprightnum) [above right of=circle2, yshift=-2.5em, xshift=-1em] {13};
        \node (outbotleftnum) [below left of=circle3, yshift=3em, xshift=-4em]{12};
        \node (outtopleftnum) [left of=circle3, yshift=1.5em]{23};
        \node (U)[above left of=circle1, xshift=2em, yshift=-1em]{\textbf{\textit{U}}};
        \node (M)[above of=circle1, yshift=-4em]{\textbf{\textit{M}}};
        \node (N)[above of=circle2, yshift=-4em]{\textbf{\textit{N}}};
        \node (L)[below right of=circle3, yshift=2.5em, xshift=-2.5em]{\textbf{\textit{L}}};
\end{tikzpicture}   
\end{document}

Which yields,

enter image description here

Any changes to the position of the labels (number and letters) will have to be made yourself but they do resemble the picture you provided.

| improve this answer | |

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.