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'm trying to draw small process flow graph, but I'm having two problems with the layout:

  • The edges from the bottom nodes B, C should curve out and around back to A, not go directly on the inside. I thought that bend left and bend right would do this, but they don't seem to have any effect.
  • The text on some edges needs more isolation from other elements. Can I specify an offset from the drawn edge to place the text?

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{arrows}
    \begin{document}
    \begin{tikzpicture}[->,>=stealth',shorten >=1pt,node distance=2.5cm,auto,main node/.style={rectangle,rounded corners,draw,align=center}]
    
    \node[main node] (1) {$A$};
    \node[main node] (2) [below left of=1] {$D$};
    \node[main node] (4) [below of=2] {$B$};
    \node[main node] (3) [below right of=1] {$E$};
    \node[main node] (5) [below of=3] {$C$};
    
    \path
    (1) edge node [left] {$d$} (2)
        edge node [right] {$e$} (3)
    (2) edge node [below] {$b$} (4)
    (3) edge node [below] {$c$} (5)
    (4) edge node [bend left] {$a$} (1)
    (5) edge node [bend right] {$a$} (1);
    
    \end{tikzpicture}
    \end{document}
    
share|improve this question
1  
For your information, the below of keys are deprecated: Difference between "right of=" and "right=of" in PGF/TikZ –  Qrrbrbirlbel Jun 27 '13 at 16:14
    
Good to know, thanks for the heads up! –  ddcc Jun 27 '13 at 20:55

2 Answers 2

up vote 7 down vote accepted
  1. You've added bend left as an option for the node, but it should be as an option to the edge, that's why they don't have any effect. You can also specify an angle, e.g. bend left=45, to change the bending.

  2. The two labels that are on top of the lines are there because the lines are vertical and you specified below as the relative node position. If you use left/right instead, or remove the placement specifier altogether, they're placed next to the lines. (Note that this automatic placement next to the path does not apply for normal lines, e.g. (a) -- (b), only for edges [I think, not very familiar with edge, so I don't how it works in detail].)

    To push them further away, you can say e.g. left=<length>.

In the below code I used swap to change which side the node is placed on. The angles for bend left/bend right were found by trial and error.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,node distance=2.5cm,auto,main node/.style={rectangle,rounded corners,draw,align=center}]

\node[main node] (1) {$A$};
\node[main node] (2) [below left of=1] {$D$};
\node[main node] (4) [below of=2] {$B$};
\node[main node] (3) [below right of=1] {$E$};
\node[main node] (5) [below of=3] {$C$};

\path
(1) edge node [swap] {$d$} (2)
    edge node  {$e$} (3)
(2) edge node [swap] {$b$} (4)
(3) edge node  {$c$} (5)
(4) edge [bend left=60] node  {$a$} (1)
(5) edge [bend right=60] node[swap]  {$a$} (1);

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks! One more question; suppose that there was more text in the D and E boxes. Is there any easy way to move the a arrows farther out to prevent them from colliding? –  ddcc Jun 27 '13 at 12:41
1  
Depending on how much text there is, you could possibly get away with just changing the bend angle. "Worst case", you have to use a different way of drawing that path, for example \draw (4) ..controls +(-3,2) and +(-3,0) .. (1) node[midway,left]{$a$};. There may well be better ways, I'm, not really an expert. –  Torbjørn T. Jun 27 '13 at 13:15
1  
@ddcc You could also use a auxiliary coordinate, say ([xshift=-1cm] 2.west) that you use on the way. –  Qrrbrbirlbel Jun 27 '13 at 21:05

You can specify the 'in' and 'out' angle of the edges, then it looks like this (i took the liberty of renaming your nodes...)

\documentclass{article}
\usepackage{tikz}
    \usetikzlibrary{arrows}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\begin{tikzpicture}[->,node distance=2.5cm,auto,main node/.style={rectangle,rounded corners,draw,align=center}]

\node[main node] (A) {$A$};
\node[main node] (D) [below left of=A] {$D$};
\node[main node] (B) [below of=D] {$B$};
\node[main node] (E) [below right of=A] {$E$};
\node[main node] (C) [below of=E] {$C$};

\path (A) edge node [left] {$d$} (D);
\path (A) edge node [right] {$e$} (E);
\path (D) edge node [right] {$b$} (B);
\path (E) edge node [left] {$c$} (C);
\path (B) edge [out=135,in=180] node [left] {$a$} (A);
\path (C) edge [out=45,in=0] node [right] {$a$} (A);

\end{tikzpicture}
\end{document}

enter image description here

Well, it seems that @Torbjørn T. just beat me to the answer by some minutes :)

share|improve this answer

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.