在 TikZ 中绘制两个节点之间等距的箭头

在 TikZ 中绘制两个节点之间等距的箭头

在下面的代码中,我垂直绘制了一个箭头。我希望它的尾部与标记为 的节点的南边界的距离(-2,1)与它的头部与标记为 的节点的北边界的距离相同0/1

\documentclass{amsart}
\usepackage{amssymb}
\usepackage{mathtools,array}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}


\begin{tikzpicture}[nodes={inner sep=0, font=\scriptsize}]

%A sequence of graphs is drawn, starting with the vertex labeled (-2,1).
\draw[fill] (-4,0) circle (1.5pt);
\node[anchor=north] at ($(-4,0) +(0,-0.25)$){$(-2, 1)$};
\node[anchor=south] at ($(-4,0) +(0,0.25)$){$\dfrac{0}{1}$};


%An arrow is drawn to the next diagram.
\draw[-latex, line width=0.8pt, shorten <=1mm, shorten >=1mm] (-4,-0.75) -- (-4,-2);

\draw (-4,-3) -- (-2,-3);
\draw[fill] (-4,-3) circle (1.5pt);
\draw[fill] (-2,-3) circle (1.5pt);
%
\node[anchor=north] at ($(-4,-3) +(0,-0.25)$){$(-2, 1)$};
\node[anchor=south] at ($(-4,-3) +(0,0.25)$){$\dfrac{0}{1}$};
%
\node[anchor=north] at ($(-2,-3) +(0,-0.25)$){$(-1, 0)$};
\node[anchor=south] at ($(-2,-3) +(0,0.25)$){$\dfrac{1}{1}$};
%
\node[anchor=north] at ($(-3,-3) +(0,-0.1)$){$2$};


\end{tikzpicture}


\end{document}

答案1

只需给节点命名,并在它们之间画箭头即可。如果缩短箭头,请对称缩短。

\documentclass{amsart}
\usepackage{amssymb}
\usepackage{mathtools,array}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}


\begin{tikzpicture}[nodes={inner sep=0,
font=\scriptsize},shorten/.style={shorten >=#1,shorten <=#1}]

%A sequence of graphs is drawn, starting with the vertex labeled (-2,1).
\draw[fill] (-4,0) circle (1.5pt);
\node[anchor=north] (A)  at ($(-4,0) +(0,-0.25)$){$(-2, 1)$};
\node[anchor=south]   at ($(-4,0) +(0,0.25)$){$\dfrac{0}{1}$};



\draw (-4,-3) -- (-2,-3);
\draw[fill] (-4,-3) circle (1.5pt);
\draw[fill] (-2,-3) circle (1.5pt);
%
\node[anchor=north] at ($(-4,-3) +(0,-0.25)$){$(-2, 1)$};
\node[anchor=south] (B) at ($(-4,-3) +(0,0.25)$){$\dfrac{0}{1}$};
%
\node[anchor=north] at ($(-2,-3) +(0,-0.25)$){$(-1, 0)$};
\node[anchor=south] at ($(-2,-3) +(0,0.25)$){$\dfrac{1}{1}$};
%
\node[anchor=north] at ($(-3,-3) +(0,-0.1)$){$2$};
%An arrow is drawn to the next diagram.
\draw[-latex, line width=0.8pt, shorten=7.5pt] (A) -- (B);
\end{tikzpicture}
\end{document}

在此处输入图片描述

如果我们添加

\fill[red,opacity=0.5] (A.south) circle[radius=1pt] (B.north) circle[radius=1pt] ([yshift=-7.5pt]A.south) circle[radius=1pt] ([yshift=7.5pt]B.north) circle[radius=1pt];

我们得到

在此处输入图片描述

说明 7.5pt 是从连接这些节点边界的箭头上取下来的。有关此内容的详细信息,请参阅\pgfpointshapeborderpgf 手册 v3.1.4 第 1123 页开始的讨论。

positioning请注意,恕我直言,如果您使用所有这些明确的坐标,效果会更好。

相关内容