I want to be able to control the distance between the edges of nodes in TikZ. In the below example, I want the left edge of "Node B" to be exactly 5 cm from the right edge of Node A. However, right of=A, node distance=5cm sets the distance between the centres of the nodes.
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows, arrows.meta, backgrounds, calc, intersections, decorations.markings, decorations.pathreplacing, positioning, shapes}
\begin{document}
\begin{tikzpicture}
\draw node[draw, rectangle, text centered] (A) {Node A};
\draw node[draw, rectangle, right of=A, node distance=5cm, text centered] (B) {Node B};
\begin{scope}[>=latex]
\draw[<->] ($(A.east)$) -- ($(B.west)$) node[midway, above] {\tiny{I want this distance to be 5 cm}};
\draw[<->] ($(A)+(0mm,-5mm)$) -- ($(B)+(0mm,-5mm)$) node[midway, below] {\tiny{not this distance}};
\end{scope}
\end{tikzpicture}
\end{document}
I found this related answer but the solution (i.e., using "right = of A" instead of "right of = A") doesn't work for me: Set node distance between borders in tikz


positioninglibrary and set thenode distanceto 5cm before you have usedright=of A? (Or implicitly:right=5cm of A.) Usually the node distance is set on an outer scope and not on the node itself. – Qrrbrbirlbel Oct 20 '23 at 17:37right=of A, node distance=5cm. It works now. Thanks for also suggesting the short notation, which I didn't know. – TheDon Oct 20 '23 at 18:08