I've created a template using pic
that has 3 cells. Then used fit to created a box I named -perimeter
around these 3 cells. Now I want to place and connect multiple pics of this type using a line (that will have a label in the future). I'm trying to do the placement and connections using pic_name-perimeter
since from what I understand we can't simply place and connect the pics directly using their name.
The issue is using below=of
or right=of
does not align pics as expected.
I've tried using anchors (now removed) like done in this example to now avail (though I could be doing it wrong).
Does someone have an idea on how I can get this working?
- I'd like to get pics to vertically or horizontally align, and
- Have the same distance between each other independently of how much text there is in the cells.
Essentially get something similar to what is shown with the nodes on the top-left corner.
MWE and respective image below.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\tikzset{
pics/state/.style n args={4}{
code = {
\begin{scope}[
node distance=0cm, outer sep=0cm,
cell/.style={draw, minimum height=0.6cm},
%every node/.append style={anchor=center}
]
\path node[cell] (a) [minimum width=1cm, align=center] {#1} node[cell] (b) [minimum width=3cm, align=center, right=of a] {#2} let \p1=($(b.south east)-(a.south west)$), \n1={veclen(\p1)} in node[cell] (c) [below=of a.south west, anchor=north west, minimum width=\n1, text width=(\pgfkeysvalueof{/pgf/minimum width}-2*\pgfkeysvalueof{/pgf/inner xsep}), align=left] {#3} node (-perimeter) [draw, red, fit=(a)(b)(c), inner sep=0pt] {};
\end{scope}
}
}
}
\begin{document}
\begin{tikzpicture}[some box/.style={rectangle, draw}, node distance=2cm]
\node[some box] (A1) {1};
\node[some box] (A2) [below=of A1] {2};
\node[some box] (A3) [below=of A2, text width=0.5cm] {3 3 3 3 3 3 3 3};
\node[some box] (A4) [below=of A3] {4};
\node[some box] (A9) [right=of A1] {9};
\draw (A9) -- (A1) -- (A2) -- (A3) -- (A4);
\pic (p1) [right=of A2] {state={1}{idle}{This text is somewhat long but that's okay because it will wrap.}{}};
\pic (p2) [below=of p1-perimeter] {state={2}{start}{This text is not long}{b3}};
\pic (p3) [below=of p2-perimeter] {state={3}{this is a long state oh no and it keeps getting longer and longer}{}{}};
\pic (p4) [below=of p3-perimeter] {state={4}{}{This is a multi-line description.\\And another line\\One last line.}{}};
\pic (p9) [right=of p1-perimeter] {state={9}{}{}{}};
\draw (p9-perimeter) -- (p1-perimeter) -- (p2-perimeter) -- (p3-perimeter) -- (p4-perimeter);
\end{tikzpicture}
\end{document}