Tikz:如何向节点锚点添加坐标?

Tikz:如何向节点锚点添加坐标?

我有一个关于定位的问题。假设我们有两个节点 (A) 和 (B)。(A) 位于 (B) 的左侧:

\node (A) {A};
\node [left of=A] (B) {B};

我们可以在(A)和(B)之间画一条箭头,像这样:

\draw[->] (A.east) -- (B.west);

但是我怎样才能在这个箭头上方稍微画一个水平箭头,例如类似的(A.east)+(0,0.5cm)--(B.west)+(0,0.5cm)?(这不起作用;这只是为了让你明白我在要求什么。)

答案1

\documentclass{standalone} 
\usepackage{tikz}

\begin{document} 
\begin{tikzpicture}[>=latex]
  \node (A) {A};
  \node [left of=A] (B) {B};
  \draw[->] (A.east) -- (B.west);
  \draw[->] ([yshift=(2.5)]A.east) -- ([yshift=(2.5)]B.west);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

虽然yshift这是对您的问题的完美回答,但请注意,您也可以使用该calc库来实现与您要求的完全相同的目标:

使用 calc 库

\documentclass[tikz,border=3.14mm]{standalone} 
\usetikzlibrary{calc}

\begin{document} 
    \begin{tikzpicture}[>=latex]
    \node (A) {A};
        \node [left of=A] (B) {B};
        \draw[->] (A.east) -- (B.west);
        \draw[->] ($(A.east)+(0,0.5)$) -- ($(B.west)+(0,0.5)$);
    \end{tikzpicture}
\end{document}

答案3

像这样(两个解决方案)

\documentclass{standalone} 
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document} 
\begin{tikzpicture}[>=latex]
  \node (A) {A};
  \node [left of=A] (B) {B};
  \draw[->] (A.east) -- (B.west);
   \draw[->,blue] (A.20) coordinate(dd)-- (dd-|B.west);
   \draw[->,red] ($(A.east)!0.5!(A.north east)$) coordinate(dd) -- (dd-|B.west);
\end{tikzpicture}
\end{document}

答案4

在此处输入图片描述

\documentclass {scrartcl}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}


\begin{tikzpicture}  
    \tikzstyle{vertex} = [ color=black, text=black, fill=black!10]
    \tikzstyle{edge} = [thick]
    
  \node[draw, vertex] (A) {A};
  \node[draw, vertex, left=of A] (B) {B};
  \draw[->, red, thick] (A.west) -- (B.east);
  \draw[->, green, thick] (A.150) -- (B.30);
  \draw[->, blue, thick] (A.210) -- (B.-30);
\end{tikzpicture}
\end{document}

相关内容