Description
I am making a graph and am using a decoration marker to make square nodes between the circular ones. That had been working fine until I wanted to add a decoration between T_t and I_t (near the top). The square is off-center and I am not sure why, it uses the same decoration code as all of the others.
So the question is why? And how do I fix it? The answer to the first will be a large step to resolving the second I'm sure.
Example Image
Code to Produce the Image
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,fit,decorations.markings,patterns}
\pagenumbering{gobble} % remove page numbering to get good cropping when using pdfcrop
\def\pnode [#1]#2{
% node for the potential function
\node[regular polygon,regular polygon sides=4, minimum size=5.0pt,fill=black,#1] (#2) {};
}
\def\snode [#1]#2#3{
% node for the state variables
\node[circle, minimum size=35.0pt , fill=lightgray,line width=0.625pt, draw=black,#1](#3){#2};
}
\def\osnode [#1]#2#3{
% for for observed state variables
\node[circle, minimum size=35.0pt , fill={rgb:red,1;green,2;blue,3},line width=0.625pt, draw=black,#1](#3){#2};
}
\tikzset{
set midblock/.code={\pgfqkeys{/tikz/midblock}{#1}},
set midblock={name/.initial=b1},
midblock/.style={
set midblock={#1},
postaction={
decorate,
decoration={
markings,
mark=at position .5 with {\pnode[]{\pgfkeysvalueof{/tikz/midblock/name}}}}
}
}
}
\tikzset{
pics/object1/.style 2 args={
code={
\begin{scope}[rotate=#2, transform shape]
\osnode[]{$Y_{r_{#1}}$}{-Yr}
\pnode[above right= of -Yr]{-f1}
\snode[below right = of -f1]{$X_{r_{#1}}$}{-Xr}
\snode[above = of -f1]{$X_{c_{#1}}$}{-Xc}
\snode[above = 20mm of -Xc]{$C_{{#1}}$}{-C}
\draw[-] (-Yr)--(-f1);
\draw[-] (-Xr)--(-f1);
\draw[-] (-Xc)--(-f1);
\draw[midblock={name=-XctoC}] (-Xc)--(-C);
\end{scope}
}
}
}
\tikzset{
pics/object2/.style 2 args={
code={
\begin{scope}[rotate=#2, transform shape]
\pnode[]{-f2}
\snode[above left=of -f2]{$T_{#1}$}{-Tt}
\snode[above right = of -f2]{$I_{#1}$}{-It}
\draw[-] (-Tt)--(-f2);
\draw[-] (-It)--(-f2);
\draw[midblock={name=testing}] (-Tt)--(-It);
\end{scope}
}
}
}
\begin{document}
\begin{tikzpicture}[remember picture]
\path pic (t1) {object1={t}{0}};
\pic [above= of t1-C] (c1) {object2={t}{0}};
\draw[-] (t1-C)--(c1-f2);
\end{tikzpicture}
\hspace{2 cm}
\begin{tikzpicture}[remember picture]
\path pic (t2) {object1={t+1}{0}};
\pic [above= of t2-C] (c2) {object2={t+1}{0}};
\draw[-] (t2-C)--(c2-f2);
\end{tikzpicture}
\begin{tikzpicture}[remember picture,overlay,every text node part/.style={align=center}] % text node stuff for multiline text
%%% Draw some edges
\draw[midblock={name=XtoX}] (t1-Xr) to [out=310,in=230] (t2-Xr);
\draw[-] (c1-It) to [out=345,in=135] (XtoX);
\draw[midblock={name=TtoT}] (c1-Tt) to [out=50,in=130] (c2-Tt);
\draw[midblock={name=ItoI}] (c1-It) to [out=50,in=130] (c2-It);
\end{tikzpicture}
\end{document}

