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.

How can I make the nodes connected without any block using Tikz? For example, I was trying to connect the arrows that returns to the do-loop when the decision making box (named as Condn) returns no. However, you can see in the Latex code below that the two arrows are disconnected! Any help?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30, drop shadow]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [draw, -latex']
\begin{document}

\begin{tikzpicture}[node distance=2cm]

\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Condn};
%\node (pro2b) [process, right of=dec1, xshift=2cm] {};
\node (pro2b) [arrow, right of=dec1, xshift=3cm] {};
\node (out1) [io, below of=dec1] {Output};
\node (stop) [startstop, below of=out1] {Stop};

\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=west] {yes} (out1);
\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
\draw [arrow] (pro2b) |- (pro1);
      % \path[-,draw] (dec1) -| node{} (inv.north);
      % \path[line]{} (inv.north) |- node[above]{no} (pro1);
\draw [arrow] (dec1) -- (out1);
\draw [arrow] (out1) -- (stop);


\end{tikzpicture}

\end{document}

I am attaching my output as well (Modified after a sample code found online).

enter image description here

share|improve this question

migrated from stackoverflow.com Feb 25 at 22:14

This question came from our site for professional and enthusiast programmers.

    
This post has been flagged for migration to TeX - LaTeX –  Werner Feb 9 at 14:51

2 Answers 2

There are various solutions to this problem. You can draw the path completely inserting an empty node with the label above:

\draw [arrow] (dec1.east) -- ++(5em,0) node[above] {no}
                          -- ++(5em,0) |- (pro1.east);

so that the whole picture draws like this:

\begin{tikzpicture}[node distance=2cm]

\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Condn};
\node (pro2b) [arrow, right of=dec1, xshift=3cm] {};
\node (out1) [io, below of=dec1] {Output};
\node (stop) [startstop, below of=out1] {Stop};

\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=west] {yes} (out1);
\draw [arrow] (dec1.east) -- ++(5em,0) node[above] {no}
                          -- ++(5em,0) |- (pro1.east);
\draw [arrow] (dec1) -- (out1);
\draw [arrow] (out1) -- (stop);

\end{tikzpicture}
share|improve this answer
    
Hi Diego, thanks a lot. –  hbaromega Feb 16 at 17:02

I have added an extra instruction box. However, the arrow below the decision box turns out to be very small and it also overlaps! Any way to extend the arrow distinguishably?

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30, drop shadow]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [draw, -latex']
\begin{document}

\begin{tikzpicture}[node distance=2cm]

\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (pro2) [process, below of=pro1] {Process 2};
\node (dec1) [decision, below of=pro2, yshift=-0.5cm] {Is $X-Y=Z$ ?};
\node (out1) [io, below of=dec1] {Output};
\node (stop) [startstop, below of=out1] {Stop};

\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro2) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=west] {yes} (out1);
\draw [arrow] (dec1.east) -- ++(5em,0) node[above] {no}
                          -- ++(5em,0) |- (pro1.east);
\draw [arrow] (dec1) -- (out1);
\draw [arrow] (out1) -- (stop);


\end{tikzpicture}

\end{document}

Output:

enter image description here

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.