2

I should end up with the first image but instead I get the second. I've tried shifting the fill, but even the smallest change shifts it a ton.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw (-2,-1.5) rectangle (3.5,1.5) node[below left]{$U$};
\fill[gray] (0,0) circle (1cm);
\fill[gray] (1,0) circle (1cm);
\draw (0,0) circle (1cm) node {$A$};
\draw (1.5,0) circle (1cm) node {$B$};
\end{tikzpicture}
\end{center}
\end{document}

Correct Output

Incorrect Output

  • 2
    Circles don't coincide because they have different coordinates. One at (1,0) and the second one at (1.5,0). – CroCo May 29 '17 at 12:40
  • Wow can't believe I didn't catch that! That's how it was coded in http://users.ju.edu/hduong/math220/venn_diagrams.pdf so I assumed it to be true. Thanks! – Seth Killian May 29 '17 at 12:41

1 Answers1

2

Like this?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw (-2,-1.5) rectangle (3.5,1.5) node[below left]{$U$};
\fill[gray] (0,0) circle (1cm);
\fill[gray] (1,0) circle (1cm);
\draw (0,0) circle (1cm) node[xshift=-5mm] {$A$};
\draw (1,0) circle (1cm) node[xshift=5mm] {$B$};
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

You might also want to use the following alternative:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw (-2,-1.5) rectangle (3.5,1.5) node[below left]{$U$};
\fill[gray] (0,0) circle (1cm);
\fill[gray] (1.5,0) circle (1cm);
\draw (0,0) circle (1cm) node {$A$};
\draw (1.5,0) circle (1cm) node {$B$};
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

CampanIgnis
  • 4,624