TikZ箭头定位

TikZ箭头定位

有了你的帮助,我可以开始使用 TikZ并创建此图像:

Original

因为我想更好地解释双箭头部分(HIS <-> Processing),所以我想扩展“HIS”块并将其拆分为两个不同的块,用虚线容器“HIS”包围:

Extended

如您所见,箭头重叠,我不知道移动箭头的正确语法,就像右侧发生的情况一样。这就是我想要实现的:

enter image description here

请注意处理出来的箭头的偏移,它被平移到了底部。这种偏移也是报告和存档之间箭头所必需的。tex 代码(我使用 pdflatex)以及围绕图像的完整文档如下:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,fit,calc}
\tikzstyle{box} = [draw, rectangle, rounded corners, thick, node distance=7em, text width=6em, text centered, minimum height=3.5em]
\tikzstyle{container} = [draw, rectangle, dashed, inner sep=2em]
\tikzstyle{line} = [draw, thick, -latex']

\begin{document}

\begin{tikzpicture}[auto]
    \node [box] (planning) {Planning};
    \node [box, below of=planning] (resources) {Resources};
    \node [box, below of=resources] (sensors) {Sensors};
    \node [box, below of=sensors] (processing) {Processing};

    \coordinate (middle) at ($(resources.west)!0.5!(sensors.west)$);
    \node [box, left of=middle, node distance=10em] (archive) {Archive};
    \node [box, left of=archive, node distance=10em] (reporting) {Reporting};

    \node[container, fit=(resources) (sensors)] (or) {};
    \node at (or.north west) [above right,node distance=0 and 0] {OR};

    \node[container, fit=(archive) (reporting)] (his) {};
    \node at (his.north west) [above right,node distance=0 and 0] {HIS};

    \path [line] (planning) -- (resources);
    \path [line] (resources) -- (sensors);
    \path [line] (sensors) -- (processing);

    \path [line] (archive) |- (planning);
    \path [line] (archive) |- (processing);
    \path [line] (processing) -| (reporting);

    \draw [line] (processing.east) -- ++(2,0) node(lowerright){} |- (planning.east);
    \draw [line] (lowerright |- or.east) -- (or.east -| resources.south east);
\end{tikzpicture}

\end{document}

我已经尝试过了(processing.south) -| (reporting)(processing) -| (reporting)但是这并没有将箭头平移到足够的位置以使其抓住垂直部分。

非常感谢任何帮助,因为我希望更好地了解 TikZ!

答案1

我的解决方案是:

enter image description here

实现它的代码是:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows,calc,fit}
\tikzset{box/.style={draw, rectangle, rounded corners, thick, node distance=7em, text width=6em, text centered, minimum height=3.5em}}
\tikzset{container/.style={draw, rectangle, dashed, inner sep=2em}}
\tikzset{line/.style={draw, thick, -latex'}}

\begin{document}

\begin{tikzpicture}[auto]
    \node [box] (planning) {Planning};
    \node [box, below of=planning] (resources) {Resources};
    \node [box, below of=resources] (sensors) {Sensors};
    \node [box, below of=sensors] (processing) {Processing};

    \coordinate (middle) at ($(resources.west)!0.5!(sensors.west)$);
    \node [box, left of=middle, node distance=10em] (archive) {Archive};
    \node [box, left of=archive, node distance=10em] (reporting) {Reporting};

    \node[container, fit=(resources) (sensors)] (or) {};
    \node at (or.north west) [above right,node distance=0 and 0] {OR};

    \node[container, fit=(archive) (reporting)] (his) {};
    \node at (his.north west) [above right,node distance=0 and 0] {HIS};

    \path [line] (planning) -- (resources);
    \path [line] (resources) -- (sensors);
    \path [line] (sensors) -- (processing);

    \path [line] (archive) |- (planning);
    \path [line] (archive) |- (processing);
    \path [line] (processing)--($(processing.south)-(0,0.5)$) -| (reporting);

    \draw [line] ($(processing.south)-(0,0.5)$) -- ++(4,0) node(lowerright){} |- (planning.east);
    \draw [line] (lowerright |- or.east) -- (or.east -| resources.south east);

    \draw[line] (archive.170)--(reporting.10);
    \draw[line] (reporting.350)--(archive.190);
\end{tikzpicture}

\end{document}

解释

Reporting为了从到框向下移动,Processing我使用了这个技巧:

\path [line] (processing)--($(processing.south)-(0,0.5)$) -| (reporting);

在框下方画一条线,使用其south锚点作为参考。当然,($(processing.south)-(0,0.5)$)新的参考也将Planning框连接到Processing

\draw [line] ($(processing.south)-(0,0.5)$) -- ++(4,0) node(lowerright){} |- (planning.east);

请注意,在这里我扩展了你的范围++(2,0)以应对新的起始位置位于框中间的事实。

Reporting最后,为了在和框之间绘制连接线,Archive我使用了您可以在中找到的定义TikZ 文档48.2 预定义形状(矩形)。

相关内容