How can you position a node relatively to another in TikZ

I would like to place a node 'B' 60 degrees of an arbitrary node 'A' between which there is a distance of 2cm. I can do this if node 'A' is at (0, 0), so 'B' would just be (60 : 2) from 'A', but what happens when 'A' is not at (0, 0)?

There are multiple ways to do this. Some of them need the calc or positioning TikZ libraries (\usetikzlibrary{calc,positioning}).

The simplest way would be (using calc TikZ-library):

\node (A) at (2,4) {<content>};
\node (B) at ($(A) + (60:2)$) {<content>};


You can also use the coordinate options ([<options>]<coordinate>) to add a shift option, which doesn't require any libraries but looks a little funny.

\node (B) at ([shift={(60:2)}]A) {<content>};

• just out of curiosity, what is the way that doesn't involve using other libraries? – Skyork Jul 19 '11 at 21:25
• @Skyork: I added this now. – Martin Scharrer Jul 19 '11 at 21:30
• Personally, I find \draw (2,4) node(A){<content>} + (60:2) node(B){<content>}; easier. – user10274 Apr 15 '13 at 13:37
• @MarcvanDongen That's the most aesthetic option so far; you should write a real answer for it. – Ryan Reich Apr 15 '13 at 14:54
• @RyanReich \path is more correct than \draw . There is nothing to draw in this case. – Alain Matthes Apr 15 '13 at 19:06

Other methods with tikz and without library :

I prefer to use \path instead of \draw Marc's suggestion in the comment. We don't to draw anything in the path.

The second method is like one possibility given by Martin \node (B) at ([shift={(60:2)}]A) {<content>};. I propose ([shift={(A)}] 60:2) If it's necessary to place others nodes relatively to A. It's preferable. We can add another possibility if we place other points it's to use a scope environment.

\documentclass{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\path (2,4) node(A){content A} + (60:2) node(B){content B};
\end{tikzpicture}

\begin{tikzpicture}

\node (A) at (2,4) {content A};
\node(B) at ([shift={(A)}] 60:2) {content B};
\end{tikzpicture}

\begin{tikzpicture}
\node (A) at (2,4) {content A};
\begin{scope}[shift={(A)}]
\node (B) at ( 60:2) {content B};
\node (C) at ( -60:3) {content C};
\end{scope}

\end{tikzpicture}
\end{document}

• Only 2 methods? – kiss my armpit Apr 15 '13 at 18:07
• 2 for me ( you forgot Martin's answer ). I think it's not useful to add complexity. It's a question about Tikz and it' s not very interesting to know that you can use \pstVerb{/xyxyadd {3 2 roll add 3 1 roll add exch} bind def}%. – Alain Matthes Apr 15 '13 at 18:51

With PSTricks, I know there are 6 methods as follows. \documentclass[border=12pt]{standalone}
\usepackage{pst-node}
\psset{unit=0.5cm,saveNodeCoors}
\begin{document}
\begin{pspicture}[showgrid](4,4)
\pnode(2,2){A}
\pscircle(A){2}
\pnode[2;60](A){B}
\psdots(A)(B)
\end{pspicture}
\begin{pspicture}[showgrid](4,4)
\pnode(2,2){A}
\pscircle(A){2}
\pnode([nodesep=2,angle=60]A){B}
\psdots(A)(B)
\end{pspicture}
\begin{pspicture}[showgrid](4,4)
\pnode(2,2){A}
\pscircle(A){2}
\rput(A){\pnode(2;60){B}}
\psdots(A)(B)
\end{pspicture}
\begin{pspicture}[showgrid](4,4)
\pnode(2,2){A}
\pscircle(A){2}
\nodexn{(A)+(2;60)}{B}
\psdots(A)(B)
\end{pspicture}
\begin{pspicture}[showgrid](4,4)
\pnode(2,2){A}
\pscircle(A){2}
\pnode(!2 60 PtoC N-A.x N-A.y xyxyadd){B}
\psdots(A)(B)
\end{pspicture}
\begin{pspicture}[showgrid](4,4)
\pnode(2,2){A}
\pscircle(A){2}
\curvepnode{60}{2 t PtoC N-A.x N-A.y xyxyadd}{B}
\psdots(A)(B)
\end{pspicture}
\end{document}


Explanation:

Let we have a node A at (2,2). For the sake of readability, I draw a circle of radius 2 with A as its center.

• Method 1: \pnode[2;60](A){B}
• Method 2: \pnode([nodesep=2,angle=60]A){B}
• Method 3: \rput(A){\pnode(2;60){B}}
• Method 4: \nodexn{(A)+(2;60)}{B}
• Method 5:

\pstVerb{/xyxyadd {3 2 roll add 3 1 roll add exch} bind def}%
\pnode(!2 60 PtoC N-A.x N-A.y xyxyadd){B}

• Method 6:

\pstVerb{/xyxyadd {3 2 roll add 3 1 roll add exch} bind def}%
\curvepnode{60}{2 t PtoC N-A.x N-A.y xyxyadd}{B}