Is it possible to anchor a TiKZ-pic
on an internal anchor?
I know (more or less) how to use TiKZ pics
and know that they are draw arround their origin. What I would like to be sure is that it's not possible to use another internal coordinate as origin.
As an example consider next code.
\tikzset{
mytest/.pic = {
\node (-A) at (0,0) {A};
\node (-B) at (0,1) {B};
\node[fit=(-A) (-B),draw] (-C) {};
}
}
It defines a pic with three nodes: A
, B
and C
being A.center
the pic
origin. A command like
\draw pic (T) at (2,1) {mytest};
draws the pic with A.center
at (2,1)
.
Now, I would like to draw this pic
but selecting B.center
(or any other internal anchor like C.120
) as anchoring (pic-origin) point. Is it possible?
In case you needed, there is some complete code:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{fit}
\tikzset{
mytest/.pic = {
\node (-A) at (0,0) {A};
\node (-B) at (0,1) {B};
\node[fit=(-A) (-B),draw] (-C) {};
}
}
\begin{document}
\begin{tikzpicture}
\draw[blue!20] (0,0) grid (3,3);
\draw pic (S) at (0,0) {mytest};
\draw pic (T) at (2,1) {mytest};
\draw (S-A.north) to [out=90,in=-90] (T-B.south);
\end{tikzpicture}
\end{document}
Question updates:
- I would like a general solution. For this particular case I know that node
B.center
is1cm
aboveA.center
and it's easy to shift the whole picture, but it's more difficult to shitf it if the origin must be atC.120
orC.100-|B.35
. Consider also somepic
with variable size nodes. - The example is just an example. I'm not trying to solve a particular problem. The question is more ... conceptual(?).
- The answer could be
no, it's not possible
. But, please, with some explanation as I always ask to my students ;-)
pic
code with ashift
option? – Claudio Fiandrino Jun 17 '14 at 12:39shift
the wholepic
so that a given point is now at(0,0)
(in thepic
s coordinate system). But doing this involved knowing at the start of thepic
where the desired anchor point is going to be. Is that easily computable in your use-cases (as it is in your example)? – Andrew Stacey Jun 17 '14 at 12:41pic
with not fixed dimensions, can I alsoshift
it? I've updated the question. – Ignasi Jun 17 '14 at 12:59pgfnewshape
and using apic
. – Ignasi Jun 17 '14 at 13:02