I'm struggling with a matrix where I want to put drawings into the cells, but would still like to reference the cells as it is possible with (text) nodes, e.g. for annotation.
I know that I can achieve this by putting text nodes and inside the text put another \tikz
and draw (2nd row in the example). However, putting a text node into the tikz picture with the sole purpose of having another TikZ picture inside feels a terrible waste. Is there a more elegant way?
I tried to use nodes in empty cells = true
, but the cells with drawings inside are not empty, they just don't have a node. So that doesn't help.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\newcommand{\punkt}{\fill (0, 0) circle (1mm);}
\newcommand{\tpunkt}{{\tikz\fill (0, 0) circle (1mm);}}
\matrix (m) [matrix of nodes,
nodes={rectangle,draw, fill=yellow}
]{
\punkt & \punkt \\
\tpunkt & \tpunkt\\
};
\draw[decorate, decoration = brace] (m-2-2.south east) -- node [below] {foo} (m-2-1.south west);
% doesn't work, because nodes m-1-1 and m-1-2 do not exist:
% \draw[decorate, decoration = brace] (m-1-1.north west) -- node [above] {bar} (m-1-2.north east);
\end{tikzpicture}
\end{document}
To clarify a bit what I'm after:
- the circles are not just circles in the real diagram, and there are different combinations of objects in the real diagram. That makes @cacamailg's answer even less elegant (and too complicated to keep the overview) than putting
\tikz{}
drawings into text nodes. -
is there a way to hand the name tikz would give to the node to the drawing macro (
\punkt{*tikz-node-name*}
? -
the
|style|
notation doesn't help, neither, because no node is generated if I have drawing commands in the cell. -
I start thinking whether defining custom shapes that include the drawing commands is the solution.
Edit 2: the real example.
Best Answer
OK, there is a lot going on here, but hopefully the comments go someway to making it clear how I've achieved this. I use a lot of nested
style
definitions, which possibly may make things tricky to follow but hopefully thestyle
names give some indication of what they do. I also use a lot of nested\foreach
loops for no other reason than I found it easier than using a matrix.Some apologies in advance for mangling the German words in the
style
definitions.