简单水平路径

简单水平路径

我正在尝试创建一个简单的水平箭头(线 1),从广告商到扫描仪,在一定距离内位于线 2 上方。由于时间太长,我试图找出正确的语法,但没有成功。我非常感谢任何帮助。

\begin{tikzpicture}[auto, 
    block_center/.style ={rectangle, draw=black, thick, fill=white,text width=12em, text centered, minimum height=12em}, 

\matrix [column sep=30mm,row sep=30mm] {  
      \node [block_center] (Scanner) {\textbf{Scanner}} ; 
    & \node  [block_center] (Advertiser) {\textbf{Advertiser}} ; \\
}; % end matrix  

\path [draw, ->] (Advertiser.west)+(0,1.5) -- node [midway,above] {line 1}  (Scanner);
  \path [draw, ->] (Advertiser.west)         -- node [midway,above] {line 2}  (Scanner) ;

\end{tikzpicture}

答案1

两个选项:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[
auto, 
block_center/.style ={
  rectangle,
  draw=black,
  thick,
  fill=white,
  text width=12em,
  text centered,
  minimum height=12em
}
]
\matrix [column sep=30mm,row sep=30mm] 
{  
  \node [block_center] (Scanner) {\textbf{Scanner}} ; 
  & \node  [block_center] (Advertiser) {\textbf{Advertiser}} ; \\
}; % end matrix  

\draw[->] ([yshift=10pt]Advertiser.west) -- node [midway,above] {line 1}  ([yshift=10pt]Scanner.east|-Advertiser.west);
\draw[->] (Advertiser.160) -- node [midway,above] {line 0}  (Scanner.east|-Advertiser.160);
\draw[->] (Advertiser.west) -- node [midway,above] {line 2}  (Scanner) ;

\end{tikzpicture}

\end{document}

在此处输入图片描述

一个更简单的图表来解释:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}
\node[draw,minimum size=2cm] (A) {A};
\node[draw,minimum size=2cm,right=2cm of A] (B) {B};
\draw (A.10) -- (B.west|-A.10);
\draw ([yshift=-20pt]A.east) -- ([yshift=-20pt]B.west|-A.east);
\end{tikzpicture}

\end{document}

在此处输入图片描述

在这两种情况下,关键在于使用垂直坐标系。语法(<name1>|-<name2>)给出的坐标具有x的 -坐标<name1>y的 -坐标<name2>

\draw (A.10) -- (B.west|-A.10);

意思是“从 到坐标为和坐标为 的A.10点画一条线”(这保证了该线是水平的。)xB.westyA.10

类似地,

\draw ([yshift=-20pt]A.east) -- ([yshift=-20pt]B.west|-A.east);

意思是“从 画一条线A.east,向下移动,到具有 的-坐标和的-坐标的20pt点,并且向下移动”(同样,这保证该线是水平的。)xB.westyA.east20pt

还有语法(<name1>-|<name2>);阅读 PGF 手册中其含义是一项家庭作业。

相关内容