TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to produce the following diagram.

enter image description here

Thanks to the following comments and one example from TeXample.net, I have done the following code. There is some problems. How can I fix them ?


    \tikzstyle{frame} = [
        rectangle, draw, 
        text width=2em, text centered,
        minimum height=4em
    \tikzstyle{line} = [draw, -latex']


\begin{tikzpicture}[node distance = 3cm]
    \node [frame] (pop) {Population};
    \node [above of=pop, left of=pop] (init) {Initialisation};
    \node [below of=pop, left of=pop] (term) {Termination};
    \node [frame, above of=pop, right of=pop] (parents)  {Parents};
    \node [frame, below of=pop, right of=pop] (off)  {Offspring};

    \path [line] (parents) -- node[right,pos=.4] {Recombination} node[right,pos=.6] {Mutation} (off);
    \path [line] (init) |- (pop);
    \path [line] (pop) -| (term);
    \path [line] (off) -| node[below,pos=.25] {Survivor selection}(pop);
    \path [line] (pop) |- node[above,pos=.75] {Parents selection} (parents);


Here is my huggly output !

enter image description here

share|improve this question
TikZ: five nodes and five edges with four nodes attached to them. – Qrrbrbirlbel Jan 23 '13 at 20:20
How can I place text near edges ? – projetmbc Jan 23 '13 at 20:21
For example: \draw[nodes=right] (Parents) edge node[pos=.33] {Recombination} node[pos=.67] {Mutation} (Offspring); Or \draw (Population) |- node[above,pos=.75] {Parent selection} (Parents); And the arrows library provides a few arrow styles (e.g. -triangle 45). Nodes not attached to the liens can be placed either manually or with the help of the positioning library. – Qrrbrbirlbel Jan 23 '13 at 20:24
Take a look, have a try. – polyfunc Jan 23 '13 at 20:29
That is the meaning of my question. I've updated it. – projetmbc Jan 23 '13 at 20:31
up vote 12 down vote accepted

I've made a couple of adjustments to the text width and node distance settings in your examples, have got to something which is nearly there, but you might want to make the arrowheads bigger?

I made the updates online using writeLaTeX, see here:


Screenshot attachedOriginal wL screenshot Update: Thanks to whoever made the edits to the wL document, they reached the updated image shown below, which is pretty close to the desired result Updated wL screenshot


    rectangle, draw, 
    text width=6em, text centered,
    minimum height=4em,drop shadow,fill=lime!40,
    rounded corners,
    draw, -latex',rounded corners=3mm,

\begin{tikzpicture}[font=\small\sffamily\bfseries,very thick,node distance = 4cm]
\node [frame] (pop) {Population};
\node [above=2cm, left of=pop] (init) {Initialisation};
\node [below=2cm, left of=pop] (term) {Termination};
\node [frame, above=2cm, right of=pop] (parents)  {Parents};
\node [frame, below=2cm, right of=pop] (off)  {Offspring};

\path [line] (parents)
 -- node[right,align=left,pos=.5] {Recombination\\[3mm]Mutation}
\path [line] (init) |- (pop.170);
\path [line] (pop.190) -| (term);
\path [line] (off) -| node[below,pos=.25, align=center] {Survivor\\ selection}(pop);
\path [line] (pop) |- node[above,pos=.75, align=center] {Parents\\ selection}(parents);

Updated screenshot

share|improve this answer
PS: If someone can improve this, please feel free to edit the wL doc. – John Hammersley Jan 24 '13 at 0:36
PPS: This is amazing - I'm now watching someone who clearly knows what they're doing editing the wL doc & making improvements...it's quite hypnotising! – John Hammersley Jan 24 '13 at 0:47
Instead of screenshots and a link to a rolling code, you should include the code itself... – Paul Gaborit Jan 24 '13 at 6:55
@JohnHammersley: Hello, thanks for the secund pretty output BUT there is two things to ameliorate. First, the arrows from/to INITIALISATION and TERMINATION overlap each other. That's not wanted (see the first picture in my question). Secundly, a lot of vertical space is wasted. Is there a way to use less vertical space ? Just one last question. Is there a way to add a backreturn so as to put "Parents" above "selection" (see the arrows from POPULATION to PARENTS). – projetmbc Jan 24 '13 at 7:28
+1 for exposing writeLaTeX! – Dror Jan 24 '13 at 8:52

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.