如何正确对齐箭头

如何正确对齐箭头

我有这个代码:

\tikzstyle{block} = [rectangle, draw, text width=2em, minimum height=2em]

\begin{tikzpicture}[node distance = 3cm, auto]
    \node [block] (a) {A};
    \node [block, right of=a] (b) {B};
    \node [block, right of=b] (c) {C};

    \path [draw, ->, ultra thick] (a) -- (b);
    \path [draw, ->, ultra thick] (b) -- (c);
    \path [draw, ->, ultra thick, dashed] (c.south) |- ++(0pt,-20pt) |- ++(-170pt,-20pt) |- (a.south);
\end{tikzpicture}

生成以下图表: 在此处输入图片描述

我想将箭头尖端方向对齐到A。 你能帮我吗?

答案1

您使用了|-太多次该操作。这些操作|-可以绘制两条线,第一条垂直的, 第二水平的

第一:你到达左下角,然后直接操作到A就可以了line to --

化学 - tikz

\documentclass[border=5pt,tikz]{standalone}
\begin{document}
\tikzstyle{block} = [rectangle, draw, text width=2em, minimum height=2em]

\begin{tikzpicture}[node distance = 3cm, auto]
    \node [block] (a) {A};
    \node [block, right of=a] (b) {B};
    \node [block, right of=b] (c) {C};
    \path [draw, ->, ultra thick] (a) -- (b);
    \path [draw, ->, ultra thick] (b) -- (c);
    \path [draw, ->, ultra thick, dashed] (c.south) |-  ++(-170pt,-20pt) -- (a.south);
\end{tikzpicture}
\end{document}

编辑:为了纠正@JasperHabicht 注意到的垂直问题

为了使最后一个箭头有效地垂直,A可以定义一个与块下方距离为的点20 pt

\coordinate[below of=a,node distance=20pt](d);

铁路

\documentclass[border=5pt,tikz]{standalone}
\begin{document}
\tikzstyle{block} = [rectangle, draw, text width=2em, minimum height=2em]

\begin{tikzpicture}[node distance = 3cm, auto]
    \node [block] (a) {A};
    \node [block, right of=a] (b) {B};
    \node [block, right of=b] (c) {C};
    \coordinate[below of=a,node distance=20pt](d); 
    \path [draw, ->, ultra thick] (a) -- (b);
    \path [draw, ->, ultra thick] (b) -- (c);
    \path [draw, ->, ultra thick, dashed] (c.south) |-  ++(d) -| (a.south);
\end{tikzpicture}
\end{document}

答案2

我宁愿不去定义新的坐标。

\documentclass[border=5pt,tikz]{standalone}
\begin{document}
\tikzset{block/.style={rectangle, draw, text width=2em, minimum height=2em}}
\begin{tikzpicture}[node distance = 3cm, auto]
    \node [block] (a) {A};
    \node [block, right of=a] (b) {B};
    \node [block, right of=b] (c) {C};
    \draw[->, ultra thick] (a) -- (b);
    \draw[->, ultra thick] (b) -- (c);
    \draw[->, ultra thick, dashed] (c.south) -- ++(0,-20pt) -| (a);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容