The placement of a tikz-pic is related to its relative (0,0) coordinate, however I'd like to think about the overall structure of the tikz-pic instead, where the distance between a tikz-pic and a node (or other tikz-pic if possible) is 1cm when you say \pic[right = 1cm of x]{mypic}, for instance. I was only able to get close to this using nested pictures. In addition to that, the behavior of the placement tools for tikz-pics seems to be different from the one for nodes.
In the following example, both placements were made with right=of resource from the positioning library (code below), but the resulting distances are different for each case: "node-to-node" (inside the tikz-pic) and "node-to-pic". Is there a way to make the positioning of a tikz-pic to have a similar behavior to a positioning of a node, i.e. the specified value would result in the distance between the borders of the tikz-pic and the related element?
Just trying to make the picture clear: there is a tikz-pic that consists of the nodes A and B, where A and B are 5cm distant from each other (as pointed by the blue line in the top, tikz makes the placement from 'border to border'). I placed then this tikz-pic 5cm to the right of the node X. Clearly the distance between the nodes X and A (black line) is very different from 5cm (blue line in the bottom as reference). I would expect the placement to be made from 'border to border' or 'center to center' (red line), however these are not the case.
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tikzpicture}
\pgfmathtruncatemacro\w{5};
% ------------------------------------------------
% code under discussion is between these commented
% dashed lines. The rest of it is there only to
% illustrate the points of the question.
\tikzset{
>=latex,
some/.pic={
\coordinate(aux);
\node[draw, left= \w/2 of aux](a){A};
\node[draw, right= \w of a](b){B};
},
}
\node[draw](x){X};
\pic[right=\w of x, local bounding box=s]{some};
%------------------------------------------------
\draw[<->](x)--(a)node[midway,above]{length$\neq$\w cm};
\draw[<->](a)--(b)node[midway,above]{length=\w cm};
%% blue lines are reference for the expected length
\begin{scope}[blue]
\coordinate[yshift=-5mm](ref1)at(x.south east);
\draw[dashed](x.south east)--(ref1);
\draw[<->](ref1)--+(\w, 0)node[midway, above]{\w cm}coordinate(ref2);
\end{scope}
\node[
draw,
right=of ref2,
anchor=north west,
align=flush center,
](aux){Between node and pic:\\border to center.};
\draw[->](aux.north west)to[out=90+45, in=45](ref2);
\begin{scope}[blue]
\coordinate[yshift=4mm](ref1)at(b.north west);
\coordinate[yshift=4mm](ref2)at(a.north east);
\draw[dashed](b.north west)--(ref1);
\draw[dashed](a.north east)--(ref2);
\draw[<->](ref1)--+(-\w, 0)node[midway,above]{\w cm};
\end{scope}
\node[
draw,
right=of ref1,
anchor=north west,
align=flush center,
](aux){Between nodes:\\border to border.};
\draw[->](aux.north west)to[out=90+45, in=45](ref1);
%% length is incorrect for the red line
\begin{scope}[red]
\coordinate[yshift=-14mm](ref1);
\coordinate[yshift=-14mm](ref2)at(s.center);
\draw[dashed](x.south)--(ref1);
\draw[dashed](s.center)--(ref2);
\draw[<->](ref1)--(ref2)node[midway, above]{$\neq$\w cm};
\end{scope}
\end{tikzpicture}
\end{document}
Update1:
Interestingly enough, if the tikz-pic consists of a node big enough to enclosure all the other contents of the tikz-pic inside it, the behavior of the positioning is pretty similar to what I ask above. However, there is still a misplacement of the nodes inside of the tikz-pic (the orange square should be located exactly over the letter A).
\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{positioning}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tikzpicture}
\tikzset{
>=latex,
some/.pic={
\node[draw, minimum size=1cm](a){A};
\node[draw=orange]at(a){};
},
}
\node[draw](x){X};
\pic[right=1cm of x, local bounding box=s]{some};
\draw[<->, blue](x.north east)--(x.north east-|a.north west);
\draw[<->, red](x.south east)--(x.south east-|s.south west);
\draw[<->, yellow!80!black](x.east)--+(1cm,0);
\end{tikzpicture}
\end{document}
Update2:
Answer for the "Update1": when used between nodes, positioning library commands (right=of and friends) will change the anchors of the nodes been placed to the closest to each other (west in this case). The same happens when used with a tikz-pic, however in this case this anchor configuration is transmitted for all the internal nodes in the tikz-pic.


local bounding boxinto the definition of thepicand this works well for me. You can also usefitin some cases. But, because I don't understand what you are asking, I don't know if you already know all this or not. – cfr Jan 21 '18 at 03:06pics behave likenodes. The node placement depends on facts about their anchors, whichpics don't have. If you really want the versatility of a node, you have to use a node.pics are quick and easy to create - the positive. But that comes at a cost: their definitions are much more simplistic than those of nodes. You don't define anchors and a border for yourpic. You don't have to. That's their beauty. It is also the source of their limitations. In particular thepositioninglibrary syntax is not going to work with them as it does with nodes. – cfr Jan 21 '18 at 03:13pic)? for your image the standard nodes with accordingly defined styles is sufficient and much simpler to use. – Zarko Jan 21 '18 at 03:34(a)has the dimensions you give it. So how on earth should TikZ know that you mean to fit the letter A? Of course there are ways to achieve a orange box around A with no space and a bigger box around this, you are just not using the appropriate commands. – Jan 21 '18 at 03:38at(a). This is not the first time I see this kind of 'misplacement' inside a tikz-pic. – tcpaiva Jan 21 '18 at 05:39tikzsetcommand, anodeand apic, i.e. just 10 lines of code). All the other things are there just to make the points of the picture clear and you can just look at the picture itself. – tcpaiva Jan 21 '18 at 05:46\node[draw=orange,anchor=center]at(a){};? ;-) – Jan 21 '18 at 05:49\pic[right=of x]{mypic};, tikz will change the anchor of all the internal nodes inmypictoeast. Makes sense. – tcpaiva Jan 21 '18 at 06:04at(a)then there are two anchors that are relevant, the one of the node(a)and the one of the new node. – Jan 21 '18 at 06:17westinstead ofeastin my previous comment. Sure, I'm pretty aware of what you are describing. However, the new node\node[]at(a){};will be placed by default using itscenteranchor over thecenteranchor of(a), unless something changed one of them, which is the case here (right=ofchange the anchor of the involved nodes that you be placed to the closest borders of each other. In the case of a tikz-pic, all internal nodes are set with the new anchor.). – tcpaiva Jan 21 '18 at 06:35