I'm trying to connect an edge to a node with the target point being off-center. I would like the edge to end with an arrow at the border of the node without going into the box.
It is easy to connect an edge to a side of a node:
\begin{tikzpicture}
\node (x) [draw,minimum size=1 cm] at (0,0) {x};
\node (y) [draw,minimum size=1 cm] at (2 cm,2 cm) {y};
\draw[->] (x) -- (y.west);
\end{tikzpicture}
But drawing to halfway between (x)
and (x.west)
continues into the node instead of stopping at the border:
\begin{tikzpicture}
\node (x) [draw,minimum size=1 cm] at (0,0) {x};
\node (y) [draw,minimum size=1 cm] at (2 cm,2 cm) {y};
\draw[->] (x) -- ($ (y.west)!0.5!(y) $);
\end{tikzpicture}
How can I make an edge with the same angle as (x) -- ($ (y.west)!0.5!(y) $)
but which draws the arrow right at the border instead of entering into the node?
Best Answer
With the TikZ library
intersections
you can find the point on the node's rectangle quite easily.We give the
y
node a path name:yborder
.We use one
\path
command to get the path from(x)
to($ (y.west)!0.5!(y) $)
and name itxyline
.With
name intersections={of=yborder and xyline}
we get coordinates namedintersections-1
,intersections-2
, …In our case there's only one intersection, so
intersection-1
will do.(The PGF/TikZ manual shows how to deal with path intersections with more than one hit.)
Code
Output