我有这个代码:
\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
--
。
\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}