4

I would like to draw the line shown in the right hand side of the attached figure from Node 3 to the line between Node 1 and Node 2.

enter image description here (Note line with should be same width as all other lines.)

I have tried to use the tikz calc package to work out the correct position for the line. But have been unable to work out the syntax.

The picture on the left has side is what my example code is currently achieving. The end point of the line is being positioned at the west on Node 3 at the y coordinate of the line from Node 1 to Node 2.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\tikzset{block/.style={rectangle,draw}}

\begin{document}
\begin{tikzpicture}

\node[block] (node1) {node1};
\node[block, right=of node1] (node2) {node2};
\draw (node1.east) -- (node2.west);

\node [block, above=of node1, xshift=-0.5cm] (node3) {node3};
\draw (node3.east) -- +(1.,0) -- (node3.east |- node1);

%\draw (node3.east) -- +(1.,0) -- ($(node3.east)+(1.,0)$ |- node1);

\end{tikzpicture}
\end{document}

3 Answers 3

6

enter image description here

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\tikzset{block/.style={rectangle,draw}}

\begin{document}
\begin{tikzpicture}

\node[block] (node1) {node1};
\node[block, right=of node1] (node2) {node2};
\draw (node1.east) -- (node2.west) coordinate[midway] (A);

\node [block, above=of node1, xshift=-0.5cm] (node3) {node3};

\draw (node3.east) -| (A);


\end{tikzpicture}
\end{document}
5

You do not even need calc for that.

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

\tikzset{block/.style={rectangle,draw}}

\begin{document}
\begin{tikzpicture}

\node[block] (node1) {node1};
\node[block, right=of node1] (node2) {node2};
\draw (node1.east) -- (node2.west);

\node [block, above=of node1, xshift=-0.5cm] (node3) {node3};
\draw (node3.east) -- +(1.,0) -- ([xshift=1cm]node3.east |- node1);

\end{tikzpicture}
\end{document}

enter image description here

2
  • Congratulation for your pgf gold tag medal !
    – Tarass
    Apr 10, 2018 at 10:36
  • @Tarass Merci. (If I were interested in badges, I'd be much more interested in you "Socratic" bade ;-)) Nice solution BTW, +1.
    – user121799
    Apr 10, 2018 at 10:40
0

You only need to modify one code

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\tikzset{block/.style={rectangle,draw}}

\begin{document}
\begin{tikzpicture}

\node[block] (node1) {node1};
\node[block, right=of node1] (node2) {node2};
\draw (node1.east) -- (node2.west);

\node [block, above=of node1, xshift=-0.5cm] (node3) {node3};


\draw (node3.east) -- +(1,0) -| ($(node1)!.5!(node2)$);

%\draw (node3.east) -- +(1.,0) -- ($(node3.east)+(1.,0)$ |- node1);

\end{tikzpicture}
\end{document}

($(node1)!.5!(node2)$) Represents the midpoint of two nodes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .