6

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}
2
  • What do you mean by "2 diagrams to each line," that the diagrams should be side by side?
    – adn
    Commented May 14, 2012 at 6:19
  • 3
    If you simply remove the blank line between the two tikzpictures (or replace it with %) they will be next to each other. Commented May 14, 2012 at 6:28

1 Answer 1

9

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

1
  • 1
    Thanks for all your help. I believe that has answered my question. :) Commented May 16, 2012 at 17:47

You must log in to answer this question.

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