3

I'm trying to draw the following figure using TikZ: enter image description here

So far I have everything except the vertical line going to I. I can't figure out how to find the mid point between S and P and then draw the line just above the line to I. I don't want to use absolute coordinates. I've tried various things but can't work out how to do it. For example I found that I can so this: \draw (A) -- (B) coordinate[midway] (M); but it didn't help me. This is the code so far:

\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}
3

There are several ways for doing this. One option is to create a temp coordinate midway between S and P, then use it to draw the perpendicular line. To calculate the mid-point, the calc library is required.

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.