1

I wanted to write the label of the node vertically along the line. the name is Simulation loop. My code is:

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{startstop}=[rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30]
\tikzstyle{process}=[rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{decision}=[rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow}=[thick,->,>=stealth]

\begin{center}

\begin{tikzpicture}[node distance=1.7cm]
\centering
\node (start) [startstop] {Initilization of model};
\node (pro1) [process, below of=start] {Load input data to workspace};
\node (prop2)[process, below of=pro1] {Calculate time of next sample iteration};
\node (prop3) [process, below of=prop2] {Calculate outputs};
\node (prop4) [process, below of=prop3] {Update discrete states};
\node (prop5) [process, below of=prop4] {Calculate derivatives};
\node (prop6) [process, below of=prop5] {Calculate output state variables};
\node (dec1) [decision, below of=prop6] {Calculate derivatives};
\node (prop7) [process, below of=dec1] {Store the final iteration output in workspace};
\node (prop8) [process, below of=prop7] {using the stored output as\\
initial condition in main model simulation};
\node (stop) [startstop, below of=prop8] {End Simulation};
\draw[arrow] (start) -- (pro1);
\draw[arrow] (pro1) -- (prop2);
\draw[arrow] (prop2) -- (prop3);
\draw[arrow] (prop3) -- (prop4);
\draw[arrow] (prop4) -- (prop5);
\draw[arrow] (prop5) -- (prop6);
\draw[arrow] (prop6) -- (dec1);
\draw[arrow] (dec1) -- (prop7);
\draw[arrow] (dec1) -- +(4,0) |- node[near start] {\hspace{3cm}Iterative loop} (prop4);
\draw[arrow] (prop7) -- (prop8);
\draw[arrow] (prop8) -- +(-7,0) |- node[near start]{\hspace{-4cm} Simulation loop} (prop2);
\draw[arrow] (prop8) -- (stop);

\end{tikzpicture}

\end{center}

2 Answers 2

1

Add sloped,above to the node options, and remove the \hspace from the node text. For the "Iterative loop"-node, remove the \hspace from that as well, and instead add right to the node options:

\draw[arrow] (dec1) -- +(4,0) |- node[near start,right] {Iterative loop} (prop4);
\draw[arrow] (prop8) -- +(-7,0) |- node[near start,sloped,above]{Simulation loop} (prop2);

Some other comments:

  • it looks like you tried to add a line break (\\) to one of the nodes. That won't work by default, but if you replace text centered with align=center in the process style, you can use \\ to make line breaks in nodes (Manual/automatic line breaks and text alignment in TikZ nodes).

  • The syntax below of=<othernode> is considered deprecated (Difference between "right of=" and "right=of" in PGF/TikZ). Instead you should load the positioning library and use below=of <othernode>. When doing this, the node distance is calculated between the edges of the nodes, rather than the center points, so a smaller node distance is needed.

    If you want the distance between nodes to be calculated between node centers, add the on grid option to the node style(s).

  • \tikzstyle{foo}=[..] is considered deprecated over \tikzset{foo/.style={..}}. There can be multiple style definitions in a single \tikzset, as in the example below.

enter image description here

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, positioning}

\tikzset{
  startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30},
  process/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, align=center, draw=black, fill=blue!30},
  decision/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, align=center, draw=black, fill=green!30},
  arrow/.style={thick,->,>=stealth}
}

\begin{document}

\begin{tikzpicture}[node distance=0.7cm]
\node (start) [startstop] {Initilization of model};
\node (pro1)  [process, below=of start] {Load input data to workspace};
\node (prop2) [process, below=of pro1] {Calculate time of next sample iteration};
\node (prop3) [process, below=of prop2] {Calculate outputs};
\node (prop4) [process, below=of prop3] {Update discrete states};
\node (prop5) [process, below=of prop4] {Calculate derivatives};
\node (prop6) [process, below=of prop5] {Calculate output state variables};
\node (dec1)  [decision, below=of prop6] {Calculate derivatives};
\node (prop7) [process, below=of dec1] {Store the final iteration output in workspace};
\node (prop8) [process,  below=of prop7] {using the stored output as\\
initial condition in main model simulation};
\node (stop) [startstop, below=of prop8] {End Simulation};
\draw[arrow] (start) -- (pro1);
\draw[arrow] (pro1) -- (prop2);
\draw[arrow] (prop2) -- (prop3);
\draw[arrow] (prop3) -- (prop4);
\draw[arrow] (prop4) -- (prop5);
\draw[arrow] (prop5) -- (prop6);
\draw[arrow] (prop6) -- (dec1);
\draw[arrow] (dec1) -- (prop7);
\draw[arrow] (dec1) -- +(4,0) |- node[near start,right] {Iterative loop} (prop4);
\draw[arrow] (prop7) -- (prop8);
\draw[arrow] (prop8) -- +(-7,0) |- node[near start,sloped,above]{Simulation loop} (prop2);
\draw[arrow] (prop8) -- (stop);

\end{tikzpicture}

\end{document}
0

enter image description here

\begin{tikzpicture}[node distance=1.7cm]
\centering
\node (start) [startstop] {Initilization of model};
\node (pro1) [process, below of=start] {Load input data to workspace};
\node (prop2)[process, below of=pro1] {Calculate time of next sample iteration};
\node (prop3) [process, below of=prop2] {Calculate outputs};
\node (prop4) [process, below of=prop3] {Update discrete states};
\node (prop5) [process, below of=prop4] {Calculate derivatives};
\node (prop6) [process, below of=prop5] {Calculate output state variables};
\node (dec1) [decision, below of=prop6] {Calculate derivatives};
\node (prop7) [process, below of=dec1] {Store the final iteration output in workspace};
\node (prop8) [process, below of=prop7] {using the stored output as};
\node (stop) [startstop, below of=prop8] {End Simulation};
\draw[arrow] (start) -- (pro1);
\draw[arrow] (pro1) -- (prop2);
\draw[arrow] (prop2) -- (prop3);
\draw[arrow] (prop3) -- (prop4);
\draw[arrow] (prop4) -- (prop5);
\draw[arrow] (prop5) -- (prop6);
\draw[arrow] (prop6) -- (dec1);
\draw[arrow] (dec1) -- (prop7);
\draw[arrow] (dec1) -- +(4,0) |- node[near start] {\hspace{3cm}Iterative loop} (prop4);
\draw[arrow] (prop7) -- (prop8);
\draw[arrow] (prop8) -- +(-7,0) |- node[
                                       rotate=90,%<-------------------add
                                       near start, 
                                       yshift=2mm
                                       ]
                                       {Simulation loop} (prop2);
\draw[arrow] (prop8) -- (stop);

\end{tikzpicture}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .