0

I'm trying to draw a scheme using Tikz nodes and arrows. Here is the scheme code:

    \begin{tikzpicture}[
        wide-block/.style={rectangle, draw=black, fill=white, thick, minimum width=4.7cm, minimum height=1cm},
        half-wide-block/.style={rectangle, draw=black, fill=white, thick, minimum width=2cm, minimum height=1cm},
        group-node/.style={rectangle, draw=black, dashed, inner sep=0.4cm}
      ]
      % fron-end node
      \node[wide-block]         (lb)                            {Load balancer};
      \node[wide-block]         (tm)    [below=of lb]           {Transaction manager};
      % back-end node
      \node[half-wide-block]    (git)   [right=of lb, xshift=1.5cm] {git};
      \node[half-wide-block]    (hook)  [right=of git]          {hook};
      \node[wide-block]         (rm)    [right=of tm, xshift=1.5cm] {Resource manager};
      \node[half-wide-block]    (prop)  [below=of rm, xshift=-1.35cm] {Proposer};
      \node[half-wide-block]    (acc)   [right=of prop]         {Acceptor};
      \node[group-node]         (fe)    [fit=(lb)(tm), label={Front-ends}] {};
      \node[group-node]         (be)    [fit=(git)(hook)(rm)(prop)(acc), label={Back-ends}] {};
      % flow
      \draw[->]         (lb.west)+(-2,0)        -- node {1}     (lb.west);
      \draw[->]         (lb)                    -- node {2}     (git);
      \draw[->]         (git.east)+(0,0.2)      -- node {3}     (hook.west)+(0,0.2);
      \draw[->]         (hook.west)+(0,-0.2)    -- node {12}    (git.east)+(0,-0.2);
      \draw[->]         (tm.west)               -- node {14}    +(-2,0);
    \end{tikzpicture}

All nodes are rendered correctly but some arrows has problems, the arrows:

      \draw[->]         (git.east)+(0,0.2)      -- node {3}     (hook.west)+(0,0.2);
      \draw[->]         (hook.west)+(0,-0.2)    -- node {12}    (git.east)+(0,-0.2);

are not drawn parallel and has broken endings: pdf-screenshot

What could be the problem with arrows? I just wanted to put arrow 3 above center line between git and hook nodes, and 12 line below this center.

1

With the calc library, you can parse node coordinates like you intended to.
And place your figures with above and below your arrows.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}

\begin{document}
    \begin{tikzpicture}[
        wide-block/.style={rectangle, draw=black, fill=white, thick, minimum width=4.7cm, minimum height=1cm},
        half-wide-block/.style={rectangle, draw=black, fill=white, thick, minimum width=2cm, minimum height=1cm},
        group-node/.style={rectangle, draw=black, dashed, inner sep=0.4cm}
      ]
      % fron-end node
      \node[wide-block]         (lb)                            {Load balancer};
      \node[wide-block]         (tm)    [below=of lb]           {Transaction manager};
      % back-end node
      \node[half-wide-block]    (git)   [right=of lb, xshift=1.5cm] {git};
      \node[half-wide-block]    (hook)  [right=of git]          {hook};
      \node[wide-block]         (rm)    [right=of tm, xshift=1.5cm] {Resource manager};
      \node[half-wide-block]    (prop)  [below=of rm, xshift=-1.35cm] {Proposer};
      \node[half-wide-block]    (acc)   [right=of prop]         {Acceptor};
      \node[group-node]         (fe)    [fit=(lb)(tm), label={Front-ends}] {};
      \node[group-node]         (be)    [fit=(git)(hook)(rm)(prop)(acc), label={Back-ends}] {};
      % flow
      \draw[->]         ($(lb.west)+(-2,0)$)        -- node[above] {1}     (lb.west);
      \draw[->]         (lb)                    -- node[above] {2}     (git);
      \draw[->]         ($(git.east)+(0,0.2)$)      -- node[above] {3}     ($(hook.west)+(0,0.2)$);
      \draw[->]         ($(hook.west)+(0,-0.2)$)    -- node[below] {12}    ($(git.east)+(0,-0.2)$);
      \draw[->]         (tm.west)               -- node[below] {14}    +(-2,0);
    \end{tikzpicture}
\end{document}

Horizontal arrows

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.