到目前为止,除了通往 I 的垂直线外,我什么都有了。我不知道如何找到 S 和 P 之间的中点,然后在通往 I 的线的正上方画一条线。我不想使用绝对坐标。我试过各种方法,但不知道该怎么做。例如,我发现我可以这样做:\draw (A) -- (B) coordinate[midway] (M); 但这对我没有帮助。这是到目前为止的代码:
\documentclass{article}
\usepackage{tikz}
\begin{tikzpicture}[>=latex',node distance = 2.5cm]
\node (S) {$S$};
\node[above of = S, node distance = 1.5cm] (I) {$I$};
\node [left of = S] (Xo) {};
\draw[->,line width = 1.2pt] (Xo) to node[above] {$v_1$} (S);
\node [right of = S] (P) {$P$};
\draw[->,line width = 1.2pt] (S) to node[below] $v_2$} (P);
\node [right of = P] (X1) {};
\draw[->,line width = 1.2pt] (P) to node[above] {$v_3$} (X1);
% This is obviously wrong
\draw[|-,line width = 1.2pt] (S) to (I) {};
\end{tikzpicture}
\end{document}
答案1
有几种方法可以做到这一点。一种选择是在S
和之间创建一个临时坐标P
,然后使用它来绘制垂直线。要计算中点,calc
需要使用库。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc} % <-- for arrow tips and calculations
\begin{document}
\begin{tikzpicture}[>=latex',node distance = 2.5cm]
\node (S) {$S$};
\node [left of = S] (Xo) {};
\draw[->,line width = 1.2pt] (Xo) -- node[above] {$v_1$} (S);
\node [right of = S] (P) {$P$};
\draw[->,line width = 1.2pt] (S) -- node[below] {$v_2$} (P);
\node [right of = P] (X1) {};
\draw[->,line width = 1.2pt] (P) -- node[above] {$v_3$} (X1);
% This obviously works
\draw[|-,line width=1.2pt] ([yshift=4pt]$(S)!.5!(P)$) --++(0,1.5cm)node[above]{$I$};
\end{tikzpicture}
\end{document}