# How to position an element relative to an anchor?

My code is:

\begin{center}
\vspace{-20pt}
\begin{tikzpicture}[mybox/.style={rectangle, draw, minimum width=10mm, minimum height=10mm}]
\foreach \addr/\val [count=\x] in {$0$,$1$/$28$,$6$/$\infty$,$6$/$\infty$,$6$/$25$,$0$,$6$/$\infty$} {
\node (node\x) [mybox] at (\x,0) {\addr};
\node[above=5mm] at (\x,0) {\footnotesize \x};
\node[below=5mm] at (\x,0) {\val};
}
\node at (node1.south west-100mm,0) [below=5mm] {Edge Weight:};
\draw[ultra thick] (node1.south west) rectangle (node7.north east);
\end{tikzpicture}
\end{center}


I get an error on the line \node (lab) at (node1.south west-100mm,0) [below=5mm] {Edge Weight:}; pertaining to the section (node1.south west-100mm,0) on using the anchor as a coordinate.

The error:

Package PGF Math Error: Unknown function 'node1' (in 'node1.south west-100mm'). \node at (node1.south west-100mm,0)

Package PGF Math Error: Unknown function 'node1' (in 'node1.south west-100mm'). ...est-100mm,0) [below=5mm] {Edge Weight:};

I want the position of the node lab to be at a distance of (-100pt,0) from the south west anchor of node0. How do I do this?

I even tried writing:

(node1.south west)+(-1,0)


But that doens't work either. How do I solve this issue?

P.S. I know writing \path (node1.south west) node at +(-35pt,-8pt) {Edge Weight:}; would solve the problem, but is there a way to do this directly without using the path command and simply using the node command?

• Use xshift inside node. \node at (node1.south west) [below=10mm,xshift=100pt] {Edge Weight:}; – Zam Nov 17 '16 at 5:51

You can use xshift:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[mybox/.style={rectangle, draw, minimum width=10mm, minimum height=10mm}]
\foreach \addr/\val [count=\x] in {$0$,$1$/$28$,$6$/$\infty$,$6$/$\infty$,$6$/$25$,$0$,$6$/$\infty$} {
\node (node\x) [mybox] at (\x,0) {\addr};
\node[above=5mm] at (\x,0) {\footnotesize \x};
\node[below=5mm] at (\x,0) {\val};
}
\node at ([xshift=-10]node1.south west) [below=5mm] {Edge Weight:};
\draw[ultra thick] (node1.south west) rectangle (node7.north east);
\end{tikzpicture}

\end{document}


With this small tweak your code produces: For what it's worth, to make the code easier to read I would replace the for-loop with

    \foreach \addr/\val [count=\x] in {0,1/28,6/\infty,6/\infty,6/25,0,6/\infty} {
\node (node\x) [mybox] at (\x,0) {$\addr$};
\node[above=5mm] at (\x,0) {\footnotesize \x};
\node[below=5mm] at (\x,0) {$\val$};
}


If you want to use the calc library, you need to write your node operation as:

 \node at ($(node1.south west)+(-1,0)$)


and you'll have: Full code:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[mybox/.style={rectangle, draw, minimum width=10mm, minimum height=10mm}]
\foreach \addr/\val [count=\x] in {$0$,$1$/$28$,$6$/$\infty$,$6$/$\infty$,$6$/$25$,$0$,$6$/$\infty$} {
\node (node\x) [mybox] at (\x,0) {\addr};
\node[above=5mm] at (\x,0) {\footnotesize \x};
\node[below=5mm] at (\x,0) {\val};
}
\node at ($(node1.south west)+(-1,0)$) [below=5mm] {Edge Weight:};
\draw[ultra thick] (node1.south west) rectangle (node7.north east);
\end{tikzpicture}
\end{document}