平行的 tikz 箭头一个接一个地呈现为 PDF

平行的 tikz 箭头一个接一个地呈现为 PDF

我正在尝试使用 Tikz 节点和箭头绘制一个方案。以下是方案代码:

    \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}

所有节点均正确渲染,但有些箭头有问题,箭头:

      \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);

并非平行,且结尾断裂: pdf 截图

箭头可能有什么问题?我只想将箭头 3 放在 githook节点之间的中心线上方,并将 12 线放在此中心下方。

答案1

使用该calc库,您可以像预期的那样解析节点坐标。
并将图形abovebelow箭头放在一起。

\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}

水平箭头

相关内容