[Tex/LaTex] venn diagrams using tikz

tikz-pgfvenn-diagrams

I found the following code for typesetting Venn Diagrams using Tikz recently. However, I would like for there to be 2 diagrams to each line. How can I accomplish this?

% 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 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 as A or B
\begin{tikzpicture}
\draw[filled, even odd rule] \firstcircle node {$A$}
                             \secondcircle node{$B$};
\node[anchor=south] at (current bounding box.north) {${(A \cap B)^{C}}$};
\end{tikzpicture}

Best Answer

If you are looking to put the figures side by side, you can use several methods. Like a table, or just moving them with a subfloat, or using minipages. The main idea is that you need to wrap your diagrams, and them adjust the alignment of the wrappers.

For example, using subfloat, you can get:

\documentclass{article}

\usepackage{tikz}
\usepackage{subfig}

\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}
\begin{figure}
\centering
% Set A and B
\subfloat{%
\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}
}
\hfil
%Set A or B but not (A and B) also known as A or B
\subfloat{%
\begin{tikzpicture}
\draw[filled, even odd rule] \firstcircle node {$A$}
                             \secondcircle node{$B$};
\node[anchor=south] at (current bounding box.north) {${(A \cap B)^{C}}$};
\end{tikzpicture}
}
\end{figure}

\end{document}

float-example

And again, you can do the same using a minipage, in which you have to indicate the width.

\documentclass{article}

\usepackage{tikz}

\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}
\begin{figure}
\centering
% Set A and B
\begin{minipage}{0.49\textwidth}
\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}
\end{minipage}
%Set A or B but not (A and B) also known as A or B
\begin{minipage}{0.49\textwidth}
\begin{tikzpicture}
\draw[filled, even odd rule] \firstcircle node {$A$}
                             \secondcircle node{$B$};
\node[anchor=south] at (current bounding box.north) {${(A \cap B)^{C}}$};
\end{tikzpicture}
\end{minipage}
\end{figure}

\end{document}

minipage-example