アンカーを基準に要素を配置するにはどうすればよいですか?

アンカーを基準に要素を配置するにはどうすればよいですか?

私のコードは次のとおりです:

\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}

アンカーを座標として使用する\node (lab) at (node1.south west-100mm,0) [below=5mm] {Edge Weight:};セクションに関連する行でエラーが発生します。(node1.south west-100mm,0)

エラー:

パッケージ PGF 数学エラー: 不明な関数 'node1' ('node1.south west-100mm' 内)。\node at (node1.south west-100mm,0)

パッケージ PGF 数学エラー: 不明な関数 'node1' ('node1.south west-100mm' 内)。...est-100mm,0) [below=5mm] {Edge Weight:};

ノードの位置を、labノード 0 の南西アンカーから (-100pt,0) の距離にしたいです。どうすればいいでしょうか?

私も書いてみました:

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

しかし、それでもうまくいきません。この問題をどうやって解決すればいいのでしょうか?

PS 書き込むことで問題が解決することはわかっています\path (node1.south west) node at +(-35pt,-8pt) {Edge Weight:};が、path コマンドを使用せずに node コマンドのみを使用してこれを直接実行する方法はありますか?

答え1

以下を使用できます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}

この小さな調整により、コードは次のようになります。

ここに画像の説明を入力してください

ちなみに、コードを読みやすくするために、forループを次のように置き換えます。

    \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$};
    }

答え2

ライブラリを使用する場合はcalc、ノード操作を次のように記述する必要があります。

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

そして次のようになります:

結果

完全なコード:

\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}

関連情報