我想要绘制这样的图表:
我的 tikz 代码如下:
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=15mm]{geometry}
\usepackage{calc}
\usetikzlibrary{matrix,arrows}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}
\begin{document}
\tikzstyle{int}=[draw, minimum width=3 cm, minimum height=1 cm]
\tikzstyle{init} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[node distance=5cm,auto,>=latex', scale = 1, transform shape]
\tikzstyle{line} = [draw, -latex']
\node [int] (a) { Box1 };
\node [int] (b) [below of=a, node distance=4 cm] {Box2};
\end{tikzpicture}
\end{document}
输出如下:
我不明白如何在 tikz 中在正确的位置绘制这样的箭头。我只知道如何在中心绘制。我该怎么做?
答案1
在这种情况下,let
可以使用语法,如以下示例所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\begin{document}
\begin{tikzpicture}
\node (a) {A};
\node[above right=of a] (b) {B};
\draw[red,->] let \p1=(a), \p2=(b) in (a) -- (\x1,0.5*\x2) -| (b);
\end{tikzpicture}
\end{document}
另一种可能性是使用节点坐标系的隐式语法,使用节点名称以及由点分隔的锚点或角度,如(a.north)
或(a.30)
;以下示例使用此方法:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning}
\tikzset{int/.style={draw, minimum width=3 cm, minimum height=1 cm},
init/.style={pin edge={to-,thin,black}}}
\begin{document}
\begin{tikzpicture}[node distance=1cm,auto,>=latex']
\node [int] (a) { Box1 };
\node [int] (b) [below of=a, node distance=4 cm] {Box2};
\node[above =of a.150,align=center] (aux1) {Input 1 \\ From 1};
\node[above =of a.30,align=center] (aux2) {Input 2 \\ From 2};
\draw[->] (aux1) -- ($(aux1)!.6!(a.150)$) -| (a.110);
\draw[->] (aux2) -- ($(aux2)!.6!(a.30)$) -| (a.70);
\draw[->] (a.south) -- +(0,-0.5) -| node[fill=white,near end,align=center,xshift=-0.75cm] (aux3) {Output 1 \\ From 1} (b.150);
\node[right =of aux3,align=center,xshift=-0.75cm] (aux4) {Input 3 \\ From 3};
\draw[->] (aux4.south) -- (aux4.south|-b.north);
\draw[->] (b.230) -- +(0,-1cm) node[anchor=north] {Yes};
\draw[->] (b.310) -- +(0,-1cm) node[anchor=north] {No};
\end{tikzpicture}
\end{document}