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 need to position the label No closer to the box check if flag set. What option should I use.

\documentclass{sig-alternate}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{process} = [rectangle, minimum width=2cm, minimum height=1cm, text centered, text width=2cm, draw=black]
\tikzstyle{connector} = [circle, minimum width=1cm, minimum height=0.5cm, text centered, text width=1cm, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\node (p0) [] {foo(K)};
\node (p1) [process, below of=p0, text width=3cm] {search for key K};
\node (p2) [process, below of=p1, yshift=-1cm, text width=3.5cm] {Create key K for insertion};
\node (p3) [process, below of=p2, yshift=-1cm, text width=3.5cm] {Attempt to insert};
\node (retF) [process, right of=p1, xshift=3cm, text width=1cm, minimum width=1cm] {return false};
\node (p4) [process, below of=p3, yshift=-1cm, text width=3cm] {check if flag set};
\node (retT) [process, right of=p3, xshift=3cm, text width=1cm, minimum width=1cm] {return true};
\node (h1) [connector, below of=p4, yshift=-1cm] {bar()};



\draw [arrow] (p1) -- node[anchor=west] {K not found} (p2);
\draw [arrow] (p1) -- node[anchor=south] {K found} (retF);
\draw [arrow] (p2) -- node {} (p3);
\draw [arrow] (p3) -- node[anchor=east] {failed} (p4);
\draw [arrow] (p3) -- node[anchor=south] {successful} (retT);
\draw [arrow] (p4) -- node[anchor=west] {Yes} (h1);
\draw [arrow] (p4.west) -- ++(-1,0) |- node[anchor=south] {No} (p1.west);
\draw [arrow] (h1.west) -- ++(-2.5,0) |- node[anchor=south] {} (p1.west);
\end{tikzpicture}
\end{document}

output

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You could use something like

\draw [arrow] (p4.west) -- ++(-1,0) node[anchor=south,pos=0.5] {No} |- (p1.west);

A complete example:

\documentclass{sig-alternate}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows,positioning}

\tikzset{ 
process/.style={
  rectangle, 
  minimum width=2cm, 
  minimum height=1cm, 
  align=center, 
  text width=2cm,
  draw
  },
connector/.style={
  circle, 
  minimum width=1cm, 
  minimum height=0.5cm, 
  align=center, 
  text width=1cm, 
  draw
},
arrow/.style={
  thick,
  ->,
  >=stealth
}
}  

\begin{document}

\begin{tikzpicture}[
node distance=1cm and 2cm
]
\node (p0) [] {foo(K)};
\node (p1) [process, below = 0.2cm of p0, text width=3cm] {search for key K};
\node (p2) [process, below =of p1, text width=3.5cm] {Create key K for insertion};
\node (p3) [process, below =of p2,text width=3.5cm] {Attempt to insert};
\node (retF) [process, right =of p1,, text width=1cm, minimum width=1cm] {return false};
\node (p4) [process, below =of p3, text width=3cm] {check if flag set};
\node (retT) [process, right =of p3,text width=1cm, minimum width=1cm] {return true};
\node (h1) [connector, below =of p4] {bar()};

\draw [arrow] (p1) -- node[anchor=west] {K not found} (p2);
\draw [arrow] (p1) -- node[anchor=south] {K found} (retF);
\draw [arrow] (p2) -- node {} (p3);
\draw [arrow] (p3) -- node[anchor=east] {failed} (p4);
\draw [arrow] (p3) -- node[anchor=south] {successful} (retT);
\draw [arrow] (p4) -- node[anchor=west] {Yes} (h1);
\draw [arrow] (p4.west) -- ++(-1,0) node[anchor=south,pos=0.5] {No} |- (p1.west);
\draw [arrow] (h1.west) -- ++(-2.5,0) |- node[anchor=south] {} (p1.west);
\end{tikzpicture}

\end{document}

enter image description here

Notice that I change \tikzstyle to \tikzset (see Should \tikzset or \tikzstyle be used to define TikZ styles?), and also I changed the problematic of= syntax to =of with the positioning library (see).

share|improve this answer
    
perfect. Thank you!! And any reason why \tikzstyle should be changed to \tikzset? –  arunmoezhi Aug 3 at 3:15
    
@arunmoezhi You're welcome. Regarding your question, ṕlease see tex.stackexchange.com/q/52372/3954 –  Gonzalo Medina Aug 3 at 3:16
    
And one more question. If my text on the arrows are long, they don't get wrapped up. For example if I change the arrow successful to it was successful it messes up the flow chart –  arunmoezhi Aug 3 at 3:17
1  
@arunmoezhi either declare an align option (requires manual line breaks) and/or a text width value (allows automatic line breaking). For example: \draw [arrow] (p3) -- node[anchor=south,align=center] {it was \\ successful} (retT); –  Gonzalo Medina Aug 3 at 3:19
    
align option worked clean!! Thanks again –  arunmoezhi Aug 3 at 3:23

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.