Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
What do you mean by "2 diagrams to each line," that the diagrams should be side by side? –  adn May 14 '12 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. –  Peter Grill May 14 '12 at 6:28

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer
1  
Thanks for all your help. I believe that has answered my question. :) –  Michael Dykes May 16 '12 at 17:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.