As an extension of the example used in the PGF documentation about pics, I propose to draw coconuts, and attach them to seagulls (as we are lacking swallows).
We will use the seagull pic defined in the manual, and introduce another very simple pic called coconut, but we want to ensure that each coconut is attached to a seagull.
Here is the definition of both pics:
\tikzset{
seagull/.pic={
% Code for a "seagull". Do you see it?...
\coordinate (-left wing) at (-3mm,0);
\coordinate (-head) at (0,0);
\coordinate (-right wing) at (3mm,0);
\draw (-3mm,0) to [bend left] (0,0) to [bend left] (3mm,0);
},
coconut/.pic={
\draw (0,0) circle[radius=2mm];
\draw[name prefix ..,very thin] (0,2mm) -- (#1-head) .. controls ++(-2mm,-0.3mm) and ++(0,-2mm) .. (#1-head) .. controls ++(2mm,-1mm) and ++(0,-2mm) .. (#1-head);
}
}
Notice that we used the key name prefix .. in the draw call for the coconut, and that a parameter is needed to tell the coconut to which seagull it is attached.
Let's try to use these pics:
\begin{tikzpicture}
\pic (Veronique) at (0.5,1) {seagull};
\pic (Virginie) at (-1,0.7) {seagull};
\pic (Emma) at (0,0) {seagull};
\pic (Coco) at (0.1,-1) {coconut=Emma};
\pic (Nut) at (-1.1,-0.8) {coconut=Virginie};
\end{tikzpicture}
Which gives the result:

figureenvironments for them. – 1010011010 Jun 17 '14 at 13:51name prefixdoes within an scope. There are some example in pgfmanual. But not whithin apicwhere is keyname prefix ..(with..not justname prefix) defined. – Ignasi Jun 17 '14 at 14:02picrefers to any node name, tikz automatically inserts before it a prefix (which is given where the pic is used). For example,\path (0,0) pic (foo) {bar};inserts the pic defined bybar/.pic, usingfooas prefix. Whenever inside the code of that pic you refer to node(X), tikz indeed interprets(fooX), since the prefix is automatically prepended.name prefix ..avoids that, so allows you to access to nodes defined in the main pic. Read the..as in the unix commmandcd ..– JLDiaz Jun 23 '14 at 16:51(current bounding box)for computing the shadow, and withoutname prefix ..option, an error appears aboutunknown node (foocurrent bounding box)(beingfoothe name prefix in this example). – JLDiaz Jun 23 '14 at 16:53