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 have seen the previous tikz example, similar with this one, but that example does not compile for me, I get 101 errors! How would one code the diagram below in tikz? Thanks, Diegis.

enter image description here

share|improve this question

1 Answer 1

One possibility:




  every node/.style={on grid},
  setA/.style={fill=blue,circle,inner sep=2pt},
  setC/.style={fill=red,rectangle,inner sep=2pt},
  every fit/.style={draw,fill=blue!15,ellipse,text width=25pt},

% set A
\node[setA,label=left:$a$] (a) {};
\node [setA,below = of a,label=left:$b$] (b) {};
\node [setA,below = of b,label=left:$c$] (c) {};
\node[above=of a,anchor=south] {$A$};

% set B
\node[inner sep=0pt,right=3cm of a] (x) {$x$};
\node[below = of x] (y) {$y$};
\node[inner sep=0pt,below = of y] (z) {$z$};
\node[above=of x,anchor=south] {$B$};

% set C
\node[setC,label=right:$m$,right = 3cm of x] (m) {};
\node[setC,label=right:$n$,below = of m] (n) {};
\node[setC,label=right:$p$,below = of n] (p) {};
\node[above=of m,anchor=south] {$C$};

% the arrows
\draw[->,shorten >= 3pt] (a) -- node[label=above:$f$] {} (x);
\draw[->,shorten >= 3pt] (b) -- node[label=above:$f$] {} (x);
\draw[->] (c) -- node[label=above:$g$] {} (y);
\draw[->,shorten <= 3pt] (x) -- node[label=above:$h$] {} (m);
\draw[->] (n) -- node[label=above:$u$] {} (y);

% the boxes around the sets
\node[fit= (a)  (c) ] {};
\node[fit= (x) (z) ] {};
\node[fit= (m) (p)] {};


enter image description here

share|improve this answer
Thank you very much, it works beautifully!! Is there a good start, a good tutorial to learn tikz? Nothing beats experience, obviously, but nothing beats a little bit of home reading either! I know nothing on the subject, while I know my way around to write pretty complex math, I am at a complete loss when it comes to drawings, and I am tired of making all visuals in Visio and then inserting them as pictures -- nothing wrong with that, but you don't get a lot of the math symbols in Visio, no Greek letters, no subscript/superscript, a lot of inconveniences... Thank you again, Diegis. –  Diegis Sep 16 '12 at 5:12
@Diegis there's the comprehensive pgfmanual (with lots of examples), the Minimal introduction to TikZ, and a good example gallery at TeXample.net. –  Gonzalo Medina Sep 16 '12 at 5:24

Your Answer


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.