4

I'm starting with TikZ, and basicaly what I'm trying to achieve is to draw what is shown in red in the next picture:

enter image description here

I think the solution is to use the help grid in order to point the line to the coordinate where I want to merge it with other, I tried for hours but it seems it's impossible for me :( can please anybody help me? Please find attached my code:

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[bottom=25mm,top=25mm, left=30mm, right=25mm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage[spanish, es-tabla, es-noshorthands, es-nosectiondot]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows}

\makeatletter
\pgfdeclareshape{datastore}{
  \inheritsavedanchors[from=rectangle]
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{south east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{north west}
  \backgroundpath{
    %  store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
 }
}
\makeatother

\begin{document}

\begin{center}
\begin{tikzpicture}[
  font=\sffamily,
  every matrix/.style={ampersand replacement=\&,column sep=2cm,row sep=2cm},
  subsistema/.style={draw,thick,rounded corners,fill=white!20,inner sep=.3cm},
  adpredect/.style={rectangle split,rectangle split parts = 3,draw,thick,rounded corners,fill=white!20,inner sep=.3cm},
  click_OK/.style={draw,thick,circle,fill=green!20},
  click_NOK/.style={draw,thick,circle,fill=red!20},
  bypass/.style={subsistema,fill=yellow!20},
  datastore/.style={draw,very thick,shape=datastore,inner sep=.3cm},
  dots/.style={gray,scale=2},
  to/.style={->,>=stealth',shorten >=1pt,semithick,font=\sffamily\footnotesize},
  every node/.style={align=center}]

  % Position the nodes using a matrix layout
  \matrix{
    \node[subsistema] (preparobox) {bla\\ bla};
      \& \node[subsistema] (lectmot) {blablablablablablabla\\ blablablabla}; \& \\

    \& \node[datastore] (colamot) {blabla}; \& \\

    \node[subsistema] (parobox) {blablablabla\\ blablabla};
      \& \node[adpredect] (subs) {%
                      blablablablablablabla     \nodepart{two}
                      blablablablablablabla    \nodepart{three}
                      blablablablablablabla   \nodepart{four}
                      }; 
      \& \node[click_OK] (clickdetectado) {OK}; \\
      \& \node[click_NOK] (clicknodetectado) {NOK}; \& \node[bypass] (acc_bypass) {BYPASS}; \\
  };

  % Draw the arrows between the nodes and label them.
  \draw[to] (preparobox) -- node[midway,above] {blabla}
      node[midway,below] {blablablabla} (lectmot);
  \draw[to] (lectmot) -- node[midway,right] {bla} (colamot);
  \draw[to] (lectmot) to[bend left=50] node[midway,below] {bla} (preparobox);
  \draw[to] (colamot) --
      node[midway,right] {blablabla\\bla} (subs);
   \draw[to] (parobox) -- node[midway,above] {bla}
      node[midway,below] {blabla} (subs);
    \draw[to] (subs) -- node[midway,above] {blabla}
     node[midway,below] {blabla} (clickdetectado);
     \draw[to] (subs) -- node[midway,left] {blablabla\\blablablabla}
     (clicknodetectado);
     \draw[to] (clicknodetectado) -- node[midway,above] {blablablabla} node[midway,below] {blablabla} (acc_bypass);
     \draw[to] (clickdetectado) to [out = -50, in = -90, looseness=2.2] node[midway,above] {blablabla} node[midway,below] {blablabla} (parobox);
     %\draw[to] (acc_bypass) to [out = -50, in = -90, looseness=1.2] (parobox);
\end{tikzpicture}
\end{center}

\end{document}
2

Result

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[bottom=25mm,top=25mm, left=30mm, right=25mm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage[spanish, es-tabla, es-noshorthands, es-nosectiondot]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, calc, intersections}

\makeatletter
\pgfdeclareshape{datastore}{
  \inheritsavedanchors[from=rectangle]
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{south east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{north west}
  \backgroundpath{
    %  store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
 }
}
\makeatother

\begin{document}

\begin{center}
\begin{tikzpicture}[
  font=\sffamily,
  every matrix/.style={ampersand replacement=\&,column sep=2cm,row sep=2cm},
  subsistema/.style={draw,thick,rounded corners,fill=white!20,inner sep=.3cm},
  adpredect/.style={rectangle split,rectangle split parts = 3,draw,thick,rounded corners,fill=white!20,inner sep=.3cm},
  click_OK/.style={draw,thick,circle,fill=green!20},
  click_NOK/.style={draw,thick,circle,fill=red!20},
  bypass/.style={subsistema,fill=yellow!20},
  datastore/.style={draw,very thick,shape=datastore,inner sep=.3cm},
  dots/.style={gray,scale=2},
  to/.style={->,>=stealth',shorten >=1pt,semithick,font=\sffamily\footnotesize},
  every node/.style={align=center}]

  % Position the nodes using a matrix layout
  \matrix{
    \node[subsistema] (preparobox) {bla\\ bla};
      \& \node[subsistema] (lectmot) {blablablablablablabla\\ blablablabla}; \& \\

    \& \node[datastore] (colamot) {blabla}; \& \\

    \node[subsistema] (parobox) {blablablabla\\ blablabla};
      \& \node[adpredect] (subs) {%
                      blablablablablablabla     \nodepart{two}
                      blablablablablablabla    \nodepart{three}
                      blablablablablablabla   \nodepart{four}
                      }; 
      \& \node[click_OK] (clickdetectado) {OK}; \\
      \& \node[click_NOK] (clicknodetectado) {NOK}; \& \node[bypass] (acc_bypass) {BYPASS}; \\
  };

  % Draw the arrows between the nodes and label them.
  \draw[to] (preparobox) -- node[midway,above] {blabla}
      node[midway,below] {blablablabla} (lectmot);
  \draw[to] (lectmot) -- node[midway,right] {bla} (colamot);
  \path (preparobox.south east) ++(-45:3pt) coordinate (preparo_se);
  \draw[semithick] (lectmot) to[bend left=50,in=135] node[midway,below] {bla}
      (preparo_se);
  \draw[semithick] ($(lectmot.south)!.6!(colamot.north)$) to[bend left=50,in=135]
      (preparo_se);
  \draw[to, shorten >=0pt] (preparo_se) -- (preparobox.south east);
  \draw[to] (colamot) --
      node[midway,right] {blablabla\\bla} (subs);
   \draw[to] (parobox) -- node[midway,above] {bla}
      node[midway,below] {blabla} (subs);
    \draw[to] (subs) -- node[midway,above] {blabla}
     node[midway,below] {blabla} (clickdetectado);
     \draw[to] (subs) -- node[midway,left] {blablabla\\blablablabla}
     (clicknodetectado);
     \draw[to] (clicknodetectado) -- node[midway,above] {blablablabla} node[midway,below] {blablabla} (acc_bypass);
     \draw[to, name path=okarc] (clickdetectado) to [out = -50, in = -90, looseness=2.2] node[midway,above] {blablabla} node[midway,below] {blablabla} (parobox);
     \path[overlay,name path=byline] (acc_bypass.south) -- ++(-120:5cm);
     \draw[semithick, line cap=round, name intersections={of=okarc and byline}]
       (acc_bypass.south) to [out=-90, in=30] (intersection-1);
     %\draw[to] (acc_bypass) to [out = -50, in = -90, looseness=1.2] (parobox);
\end{tikzpicture}
\end{center}

\end{document}

Remarks:

  • Both lines are ending with the same input angle at the south east corner of preparobox. Two arrow heads are probably not looking too good, thus I let the lines end 3 pt before without arrow head and added an arrow line from 3 pt to the south east corner. Since the box has rounded corners, I have reduced shorten > to 0 pt.

  • As target for the lower line I have used the intersection between the line from "OK" (clickdetectado) to parobox and an invisible straight line from acc_bypass.south with angle -120. The intersection point is then calculated with the help of library intersections.

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.