如何在 tikz 中绘制弯曲的箭头?

如何在 tikz 中绘制弯曲的箭头?

我得到了这样的信息: 在此处输入图片描述

这看起来确实不太好。弯曲的箭头穿过了方块。有没有更好的绘制弯曲箭头的方法或其他解决方案?

我正在输入我的代码:

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[margin=15mm]{geometry}
\usetikzlibrary{shapes,arrows,fit,calc,positioning}


\begin{document}

\begin{tikzpicture}[thick]
\tikzset{input/.style={}}
\tikzset{block/.style={rectangle,draw}}
\tikzstyle{pinstyle} = [pin edge={to-,thick,black}]

\node [input, name=input] {};
\node [block, right=0.5 cm of input,minimum width=1.5cm, minimum height=2.5cm] (a) {};
\node [block, right of=a,minimum width=1.5cm, minimum height=5cm,node distance=3cm] (b) {};
\node [block, right of=b, minimum width=2cm, minimum height=5cm,node distance=3cm] (c) {};
\node [block, right of=c,minimum width=1.5cm, minimum height=5cm,node distance=3cm] (d) {};
\node [block, right of=d, minimum width=2cm, minimum height=5cm,node distance=3cm] (e) {};
\node [right =0.5 cm of e] (output) {};

\begin{scope}[->,>=latex]

\draw[->] (input) -- (a);

\node at (b.center) {\footnotesize{z}};

\draw[->] ([yshift=1.5 cm]c.north west) node[left]{\footnotesize{$Ack_1$}} -| ([xshift=0.25 cm]e.north);
\draw[->] ([yshift=1.5 cm]c.north west) -| ([xshift=0.25 cm]c.north);
\draw[->] ([yshift=1 cm]c.north west) node[left]{\footnotesize{$Ack_0$}} -| ([xshift=-0.25 cm]e.north);
\draw[->] ([yshift=1 cm]c.north west) -| ([xshift=-0.25 cm]c.north);
\draw[->] (e) -- (output);

\foreach \i in {2,...,-2}{% 
\draw[->] ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) ;}

\foreach \i in {-2,...,2}{% 
\draw[->] ([yshift=\i * 0.8 cm]b.east) -- ([yshift=\i * 0.8 cm]c.west) ;}

\foreach \i in {-2,...,2}{% 
\draw[->] ([yshift=\i * 0.4 cm]a.east) to [out=-60,in=-120] ([yshift=\i * 0.8 cm]d.west) ;}

\foreach \i in {-2,...,2}{% 
\draw[->] ([yshift=\i * 0.8 cm]d.east) -- ([yshift=\i * 0.8 cm]e.west) ;}

\end{scope}
\end{tikzpicture}

\end{document}

答案1

您可以在圆弧路径中添加两个点

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[margin=15mm]{geometry}
\usetikzlibrary{shapes,arrows,fit,calc,positioning}


\begin{document}

\begin{tikzpicture}[thick]
\tikzset{input/.style={}}
\tikzset{block/.style={rectangle,draw}}
\tikzstyle{pinstyle} = [pin edge={to-,thick,black}]

\node [input, name=input] {};
\node [block, right=0.5 cm of input,minimum width=1.5cm, minimum height=2.5cm,red] (a) {};
\node [block, right of=a,minimum width=1.5cm, minimum height=5cm,node distance=3cm,blue] (b) {};
\node [block, right of=b, minimum width=2cm, minimum height=5cm,node distance=3cm,purple] (c) {};
\node [block, right of=c,minimum width=1.5cm, minimum height=5cm,node distance=3cm,green] (d) {};
\node [block, right of=d, minimum width=2cm, minimum height=5cm,node distance=3cm] (e) {};
\node [right =0.5 cm of e] (output) {};

\begin{scope}[->,>=latex]

\draw[->] (input) -- (a);

\node at (b.center) {\footnotesize{z}};

\draw[->] ([yshift=1.5 cm]c.north west) node[left]{\footnotesize{$Ack_1$}} -| ([xshift=0.25 cm]e.north);
\draw[->] ([yshift=1.5 cm]c.north west) -| ([xshift=0.25 cm]c.north);
\draw[->] ([yshift=1 cm]c.north west) node[left]{\footnotesize{$Ack_0$}} -| ([xshift=-0.25 cm]e.north);
\draw[->] ([yshift=1 cm]c.north west) -| ([xshift=-0.25 cm]c.north);
\draw[->] (e) -- (output);

\foreach \i in {2,...,-2}{% 
\draw[->] ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) ;}

\foreach \i in {-2,...,2}{% 
\draw[->] ([yshift=\i * 0.8 cm]b.east) -- ([yshift=\i * 0.8 cm]c.west) ;}

\foreach \i in {-2,...,2}{% 
\draw[->] ([yshift=\i * 0.4 cm]a.east) to [out=-0,in=90]  ([xshift={\i * 0.15 cm-0.75cm}]b.south west) to [out=-90,in=-90]  ([xshift={-\i * 0.15 cm+0.75cm}]c.south east)  to [out=90,in=-180]  ([yshift=\i * 0.8 cm]d.west) ;}

\foreach \i in {-2,...,2}{% 
\draw[->] ([yshift=\i * 0.8 cm]d.east) -- ([yshift=\i * 0.8 cm]e.west) ;}

\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

建议不要使用弯曲的箭头并简化图表。

在此处输入图片描述

您要传达的是,从输入块开始,该过程被拆分为两个子过程。Ack 行可以在顶部和底部重复。

我通常会在 OpenOffice 等程序中绘制图表,然后使用 TikZ 绘制它们以包含在文档中。使用 OpenOffice 大约需要 5 分钟,使用 TikZ 则需要四十五分钟(静止)到一个小时才能正确绘制,所以我不会发布任何代码。如果您采用这种方法,请发布您的代码。

答案3

Yiannis Lazarides 解决方案的代码:

\begin{tikzpicture}[thick]
\tikzset{input/.style={}} 
\tikzset{block/.style={rectangle,draw}}
\tikzstyle{pinstyle} = [pin edge={to-,thick,black}]

\node [input, name=input] {};
\node [block, right=0.5 cm of input,minimum width=3cm, minimum height=5cm] (a) {};
\node [name = z] at ([xshift=4 cm]a.east) {};
\node [block, above=0.5 cm of z, minimum width=3cm, minimum height=5cm] (b) {};
\node [block, right=2.5 cm of b, minimum width=3cm, minimum height=5cm] (c) {};
\node [block, below=0.5 cm of z, minimum width=3cm, minimum height=5cm] (d) {};
\node [block, right=2.5 cm of d, minimum width=3cm, minimum height=5cm] (e) {};



\begin{scope}[>=latex]

\draw[->] ([yshift=1.5 cm,xshift=0.25 cm]c.north) node[right] {\footnotesize{$Ack_1$}} -- ([xshift=0.25 cm]c.north);
\draw[->] ([yshift=1.5 cm,xshift=-0.25 cm]c.north) node[left] {\footnotesize{$Ack_0$}} -- ([xshift=-0.25 cm]c.north);

\draw[->] (input) -- (a);

\draw ([yshift=1 cm,xshift=-0.25 cm]c.north)  -- ([yshift=1 cm,xshift=1 cm]c.north east);
\draw ([yshift=0.5 cm,xshift=0.25 cm]c.north)  -- ([yshift=0.5 cm,xshift=0.5 cm]c.north east);

\draw ([yshift=1 cm,xshift=1 cm]c.north east) -- ([yshift=-0.25 cm,xshift=1 cm]c.south east);
\draw ([yshift=0.5 cm,xshift=0.5 cm]c.north east) -- ([yshift=-0.75 cm,xshift=0.5 cm]c.south east);

\draw ([yshift=-0.25 cm,xshift=1 cm]c.south east) -- ([yshift=1.01 cm,xshift=-0.25 cm]e.north);
\draw ([yshift=-0.75 cm,xshift=0.5 cm]c.south east) -- ([yshift=0.51 cm,xshift=0.25 cm]e.north);

\draw[->] ([yshift=1.01 cm,xshift=-0.25 cm]e.north) -- ([xshift=-0.25 cm]e.north);
\draw[->] ([yshift=0.51 cm,xshift=0.25 cm]e.north) -- ([xshift=0.25 cm]e.north);

\foreach \i in {2,...,-2}{% 
\draw[->] ([yshift=\i * 0.8 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) ;}

\foreach \i in {2,...,-2}{% 
\draw[->] ([yshift=\i * 0.8 cm]a.east) -- ([yshift=\i * 0.8 cm]d.west) ;}

\foreach \i in {2,...,-2}{% 
\draw[->] ([yshift=\i * 0.8 cm]b.east) -- ([yshift=\i * 0.8 cm]c.west) ;}

\foreach \i in {2,...,-2}{% 
\draw[->] ([yshift=\i * 0.8 cm]d.east) -- ([yshift=\i * 0.8 cm]e.west) ;}


\end{scope}
\end{tikzpicture}

其结果为: 在此处输入图片描述

相关内容