4

i'm not able to draw arrows like red ones :(. any suggestions? Also this yellow block type doesn't seems cool..

enter image description here

code is here

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=gray!10]
\tikzstyle{decision} = [diamond,aspect=2, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=yellow!10]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{figure}
\centering
\begin{tikzpicture}[node distance=2.5cm,auto,>=latex']

\node (1) [process] {downsampling};
\node (2) [process, below of=1] {framing};
\node (3) [process, below of=2] {iterazione};
\node (4) [process, below of=3] {subframing};
\node (5) [process, below of=4] {sub-iterazione};
\node (6) [decision, below of=5,yshift=-1cm] {possibile decadimento e non fine del sub frame};
\node (7) [process, below of=6,yshift=-1cm] {calcolo \rt};
\node (8) [process, left of=7, xshift=-3cm] {stima \rt globale};

\draw [arrow] (1) -- (2);
\draw [arrow] (2) -- (3);
\draw [arrow] (3) -- (4);
\draw [arrow] (4) -- (5);
\draw [arrow] (5) -- (6);
\draw [arrow] (6) -- node[anchor=east] {sì} (7);
\draw [arrow] (6) |- node[anchor=south,left] {no} (3);
\draw [arrow] (7) -- (8);

\end{tikzpicture}
\end{figure}

2 Answers2

5

There is a lot of ways to do this thing. Here is my attempt to teach you what is happening here:

enter image description here

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, shapes}

\begin{document}
    \begin{tikzpicture}[>=Stealth]
        % Style Definition
        \tikzset{process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=gray!10, node distance=2.5cm}}
        \tikzset{decision/.style={diamond,aspect=2, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=yellow!10, node distance=2.5cm}}

        % Node Placement
        \node[process] (START) {First Process};
        \node[process, below of=START] (SECOND) {Second Process};
        \node[decision, below of=SECOND] (DEC) {First Decision};
        \node[process, below of=DEC] (THIRD) {Third Process};

        % Node Connection
        \draw[->] (START) -- (SECOND);
        \draw[->] (SECOND) -- (DEC);
        \draw[->] (DEC) -- coordinate (midDT) (THIRD);
        \draw[->] (DEC) -- +(-2.5,0) |- (START);
        \draw[->] (midDT) -- +(2.5,0) |- (SECOND);
    \end{tikzpicture}
\end{document}

As you can see there is three process nodes and one decision node. Every style applied to them is defined by using a \tikzset command rather than \tikzstyle because of this question/answers. Note that within each style definition is a node distance key that facilitates node placement when you use relative positioning, to avoid a lot of shifting declarations.

The flowchart is drawn in three parts: One for style definition, without them the nodes would not be easily fancy styled, this includes node distance declarations described above; one for nodes placement; and one for node interconnections. I draw every interconnection by using the \draw command and path operations (--, |-) between node names that point to coordinates into the 2D plane.

When the (THIRD) node is connected to (DEC) I've used a coordinate (<name>) to define the midpoint of the connection line. The you can draw your desired lines using two path operations: first one, to go from a node/coordinate to outside that node/coordinate by some desired amount (I chose 2.5) applied only to the x coordinate, that's what you can see (NODE) -- +(2.5,0), the -- path operation orders TikZ to go horizontally from one coordinate to another; second and last, to go from this last coordinate to a desired node, first vertically a then horizontally, ordering TikZ to do this using a |- path operation: +(2.5,0) |- (NODE). I've used arrows.meta library (available from PGF/TikZ 3.0.0) to provide better Stealth arrows to draw.

I know you know many of these things but may help someone else.

osjerick
  • 6,970
2

I'm preaty sure that I already answer on similar question ... anyway, here is slighly modified my answer:

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{arrows.meta,calc,chains,shapes.geometric}

    \begin{document}
\begin{tikzpicture}[
    node distance = 5mm and 7mm,
      start chain = going below,
     arrow/.style = {thick,-{Stealth[length=5pt,width=4pt]}},
    basics/.style = {draw=black,
                     minimum width=30mm, minimum height=7.5mm, align=center,
                     join= by arrow, on chain},
      start/.style = {rectangle, rounded corners, fill=red!30, basics},
      block/.style = {rectangle, fill=blue!30, basics},
   decision/.style = {diamond, aspect=2,text width=44mm, inner xsep=-1em, basics},
    ]
\node (n1) [start] {downsampling};
\node (n2) [block] {framing};
\node (n3) [block] {iterazione};
\node (n4) [block] {subframing};
\node (n5) [block] {sub-iterazione};
\node (n6) [decision] {possibile decadimento e non fine del sub frame};
\node (n7) [block] {calcolo ??};
\node (n8) [block, left=of n7.west] {stima ?? globale};

\draw [red,arrow] (n6.west) node[above left]   {no} -- + (-7mm,0) |- (n3.west);
\draw [red,arrow] ($(n6.south)!0.5!(n7.north)$) node[left] {si} -| ([xshift=5mm] n6.east) |- (n2);
\end{tikzpicture}
    \end{document}

Above MWE generate the following picture:

enter image description here

Zarko
  • 296,517
  • @user2054758, well, your flowchart is not clear to me. The decision is unusual: it has deadlock cycle. As you see, I separate draw only loops, connection between successive block are done by joint option. So, if you need to change anything, this should be easy. Happy TeXing! – Zarko Nov 07 '15 at 19:32
  • a question, i have this error: I can't find file `tikzlibraryarrows.meta.code.tex' ...y{arrows.meta,calc,chains,shapes.geometric} – user2054758 Nov 07 '15 at 19:34
  • Which version of TikZ you have? Library arrows.meta exist from version 3.0.0 further (recent is 3.0.1a). Try to upgrade your TikZ instalation. – Zarko Nov 07 '15 at 19:42
  • @user2054758 You can be thankful by upvoting Zarko's answer. ;) – osjerick Nov 07 '15 at 21:14
  • i just replaced this content: \begin{tikzpicture}[>=latex'] in both solutions and it worked fine – user2054758 Nov 07 '15 at 21:19
  • 1
    @user2054758, you no need to use arrows.meta library ... however, it intention is to replace arrows library. In this context I prefer to use new one. If you update your TikZ (as you said above), than use of arrows.meta should not be a problem. I strongly encorage you to read TikZ manual. It is hugre :-(, but for start going through chapter "TikZ is kein ziechenprogram will give you good basic knowledge about TikZ. – Zarko Nov 07 '15 at 21:26