I am trying to nest tikz graph environments into the nodes of a tikz graph environment:
\begin{tikzpicture}
\graph [layered layout]{
ABABAB -> {
AB -> {A, B},
BA -> {A, B}
};
};
\end{tikzpicture}
I got this so far and I need to make each node its own graph with a similar layout.
I also want to be able to connect nodes from the inner graphs with nodes of the outer graph.
I could create all nodes individually and connect them, with nested nodes like this:
\node [draw] at (0,0) (container1) {
\begin{tikzpicture}
\node at (0,0) (container1label) {Node 1};
\node [draw,below=0.4 of container1label] (child1) {Node 1's Child};
\end{tikzpicture}
};
But I would like to have the layout automatically taken care of.
Ideally I would create the outer graph with invisible edges, so the layout is appropriate, and then connect the inner nodes of the graphs with each other manually.
Is there some way to nest a tikzpicture in a node created in a \graph environment?
Edit:
To make it more clear, this is what I am trying to model. A formal grammar composed of rules. I need an outer node for each left side of a rule and inside these outer nodes I would like to be able to create new nodes for each symbol and connect them with their corresponding outer nodes.
For example, I would like the outer node of abcdef to contain nodes for ab, cde, f, a, bc and def (preferrably easily laid out as shown in the picture, in two lines) and then I need an edge from each of these inner nodes to their corresponding outer node, which in turn contains its rule's symbols.
A simpler solution might be to only connect the outer nodes with each other if they have rules pointing to each other, but I wouldn't even know how to define a math text content for each node in the graph environment. Preferrably I would like to connect each inner symbol node with each outer rule node, though.
So similar to this:




tikzpictures can be nested, and if so, each node could be one, with a "big" one wrapped around all the little ones. – barbara beeton Sep 12 '23 at 23:14tikzpictures can be nested, but I don't know of a way to define the contents of a node declared in agraphenvironment. There is thetypesetkey, which allows one to map the text content of all nodes to something new, but I can't put atikzpicturein there and I would like the contents to be individual for each node. – stimulate Sep 12 '23 at 23:19tikzpictures shouldn't be nested. As with most rules, there are cases where you may get away with it, but it is (almost?) always the wrong thing to do. See, for example, https://tex.stackexchange.com/questions/46598/problem-with-overlay-when-a-tikzpicture-is-inside-another-tikzpicture. – cfr Sep 12 '23 at 23:19tikzpictures. The results of trying to do so are (almost) always unpredictable and (almost) always not what you want. The settings of the outside picture will change the output of the inner one, while the stuff inside the inner one won't be accessible in the outer one. You can use things such astikzmarkto create subnodes you can refer to outside the currenttikzpicture(or outside one) and you can useremember picture, for example, but nesting them is a can of worms. – cfr Sep 12 '23 at 23:26forestif you don't need the automatic layout facilities of LuaTeX. But it isn't clear from your current question really what you're dealing with. – cfr Sep 12 '23 at 23:31forest. I am trying to render a DAG structure where each node contains inner nodes. These inner nodes point to nodes in the outer graph.I am currently looking at defining all the inner nodes in a single graph and then surrounding them with nodes using
– stimulate Sep 12 '23 at 23:47fit. But here the problem is I can't reference the wrapper nodes in the original graph. There is alsodeclarefor tikz graph macros.. but it doesn't create a node for the entire macro. I just need to define a graph within a node..tikzpicture, you can. There are even ways of referencing nodes which you'll only draw later in the picture. (You get nonsense output on the first run, but that's just like the ?? for cross-references. Just more colourful.) – cfr Sep 13 '23 at 01:47tikzpicture. Just put it in a node? (I haven't used the graph stuff much, so the answer could easily be a flat 'No'.) – cfr Sep 13 '23 at 01:48graphdrawingsupports sublayouts and if that doesn't do what you need and as long as you don't need a transformation you might be able to use a PGF/TikZ matrix which is very close to putting a TikZ picture inside a node but actually supported. Whethergraphdrawingcan deal with it is another story, though. – Qrrbrbirlbel Sep 13 '23 at 07:39