4

I'd like to place a node relative to a boundary anchor on another node. The following code illustrates what I want to be able to do.

\begin{tikzpicture}
    \node[draw] (A) {A}
    \node[left of=(A.160)] (b) {b};
    \draw [->] (b) -- (A.160);
\end{tikzpicture}

where the objective is to have the arrow from b -> A be horizontal.

1 Answer 1

6

Basic Solution

You almost had it right already:

\documentclass[tikz]{standalone}

\begin{document}
    \begin{tikzpicture}
        \node[draw] (A) {A};
        \node[left=1cm] at (A.160) (b) {b};
        \draw [->] (b) -- (A.160);
    \end{tikzpicture}
\end{document}

result

Alternative

Your code looks like maybe you were trying to use the positioning library. If that is the case, here's one way to do it using that library:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}

\begin{document}
    \begin{tikzpicture}[node distance=1cm]
        \node[draw] (A) {A};
        \node[left=of A.160] (b) {b};
        \draw [->] (b) -- (A.160);
    \end{tikzpicture}
\end{document}

Possibly Better Alternative

I'm just guessing here, but maybe what you were trying to do was simply to have multiple equally spaced „inputs“ to a single node. The problem with the angle anchors is that the angles that look good depend on the aspect ratio of the node. Here's a simple example using the calc library:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
    \begin{tikzpicture}[node distance=1cm]
        \node[draw] (A) {A};
        \coordinate (A input 1) at ($(A.north west)!0.25!(A.south west)$);
        \coordinate (A input 2) at ($(A.north west)!0.75!(A.south west)$);
        \node[left=1cm] at (A input 1) (b) {b};
        \node[below left=0.3cm] at (A input 2) (c) {c};
        \draw [->] (b) -- (A input 1);
        \draw [->] (c) |- (A input 2);
    \end{tikzpicture}
\end{document}

other output

The coordinate specification ($(A.north west)!0.25!(A.south west)$) calculates the position 25% of the way between the two given corners of (A). I define coordinates to avoid having to type the number twice.

0

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.