0

The image of the code I need to make a line for the bottom of step 3 to step 4.

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{varwidth}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{amsthm}
\usepackage{newfloat}
\usepackage{multirow}
\usepackage{indentfirst}
\usepackage{tabularx}
\usepackage{xcolor,colortbl}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc,shapes.multipart,chains,arrows}

    \tikzstyle{line} = [draw, -latex']
\tikzstyle{rect10} = [draw, rectangle, fill = red!25, text width = 8em, text centered, minimum height = 2em]
\tikzstyle{rect11} = [draw, rectangle, fill = red!45, text width = 8em, text centered, minimum height = 2em]
\tikzstyle{rect12} = [draw, rectangle, fill = blue!25, text width = 6em, text centered, minimum height = 3em]
\tikzstyle{rect14} = [draw, rectangle, fill = blue!40, text width = 8em, text centered, minimum height = 3em]
\tikzstyle{rect13} = [draw, rectangle, fill = purple!45, text width = 6em, text centered, minimum height = 4em]
\tikzstyle{diam3} = [draw, diamond, fill = green!30,text width=8em,text badly centered, inner sep=0pt]


\begin{figure}[h]
\begin{tikzpicture}
   \node [rect11] (step1){Initialize
Distances};
   \node [rect10, below of=step1,node distance=2cm] (step2){Initialize 
Dictionary};
   \node [diam3, rounded corners, below of= step2,node distance=3.5cm] (step3){Dijkstra
   (V-1 times)};
      \node [diam4, rounded corners, right of= step3,node distance=4cm] (step4){Update
   Dictionary};
   \path [line] (step1)--(step2);
   \path [line] (step2)--(step3);
   \path [line,rounded corners] (step3)--++(-3,-2) --++(1,1)(step4);;
   \path [line,rounded corners] (step4)--+(-2,2) --(step3);
\end{tikzpicture}
\end{figure}
  • Hi, welcome. If you select the code in your question and hit Ctrl + K it will be marked up properly, as you can see from my edit. Your question is a bit unclear though, exactly what kind of line do you want to draw? – Torbjørn T. Nov 20 '17 at 16:22
  • \path [line,rounded corners] (step3)--++(2,-2) --(step4); – Ignasi Nov 20 '17 at 16:40
2

Ignasi mentioned one possible solution in his comment. Another one, that doesn't depend on the distance between the two nodes, is

\path [line] (step3) to[out=-45,in=-135,looseness=2.2] (step4);
\path [line] (step4) to[out=135,in=45,looseness=2.2]   (step3);

It doesn't produce exactly the same result, but it's fairly close.

Below I've made a few other modifications to your code as well:

  • Change from \tikzstyle{<stylename>} = [<settings>] to \tikzset{<stylename>/.style={<settings>} for defining styles. There is some discussion about this in Should \tikzset or \tikzstyle be used to define TikZ styles? While not documented, \tikzstyle works, and will continue to work, so in the end it's up to you which syntax to use.

  • Nested styles: you had multiple rectangle styles which were very similar. You can however put one style inside another, so it might make sense to define a basic rect style,

    rect/.style={draw, rectangle, text width = 8em, text centered, minimum height = 2em},
    

    and then base the other styles on this, e.g.

    rect10/.style={rect, fill = red!25},
    
  • Make use of the positioning library. With that library you write <position>=of <othernode> instead of <position> of=<othernode>. The latter syntax, which you used, is actually deprecated (see Difference between "right of=" and "right=of" in PGF/TikZ).

    With the code as below, the distance is measured between the borders of the nodes, so you don't have to specify a different node distance in each case.

output of code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc,shapes.multipart,chains}

\tikzset{
    line/.style={draw, -latex'},
    rect/.style={draw, rectangle, text width = 8em, text centered, minimum height = 2em},
    diam/.style={draw, diamond, rounded corners, text width=8em,text badly centered, inner sep=0pt},
    rect10/.style={rect, fill = red!25},
    rect11/.style={rect, fill = red!45},
    rect12/.style={rect, fill = blue!25, text width = 6em},
    rect14/.style={rect, fill = blue!40},
    rect13/.style={rect, fill = purple!45, text width = 6em},
    diam3/.style={diam, fill = green!30},
    diam4/.style={diam, fill = blue!30}
}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}
   \node [rect11]                 (step1) {Initialize Distances};
   \node [rect10, below=of step1] (step2) {Initialize Dictionary};
   \node [diam3,  below=of step2] (step3) {Dijkstra (V-1 times)};
   \node [diam4,  right=of step3] (step4) {Update Dictionary};
   \path [line] (step1) -- (step2);
   \path [line] (step2) -- (step3);
   \path [line] (step3) to[out=-45,in=-135,looseness=2.2] (step4);
   \path [line] (step4) to[out=135,in=45,looseness=2.2]   (step3);

\end{tikzpicture}
\end{figure}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.