# Strange behavior of child node inside matrix node

The child node behaves strangely within a matrix node. And it only appears in one matrix node. I know that there are methods to draw it without the matrix node in this simple case. But essentially I need to draw the Hasse diagram of a partially ordered set, where each element is a tree. So it would be nice if the matrix node is kept. Anyway, the strange behavior is also interesting. One may also check child node strangely leaning to the right to see that it also appears when using nested tikzpicture. I am suggested to raise a new question for the case of matrix node.

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
[level distance = 10mm]

\node [matrix, label=left:{$T_1$}] (T1)
{
\begin{scope}
[every node/.style={draw, circle, inner sep=1pt, minimum size = 1mm}]
\node {}
child {node {} child {node {}}}
child {node {} child {node {}}}
child {node {} child {node {}}};
\end{scope}\\
};

\node [matrix, right = of T1, label=left:{$T_2$}] (T2)
{
\begin{scope}
[every node/.style={draw, circle, inner sep=1pt, minimum size = 1mm}]
\node {}
child {node {} child {node {}}}
child {node {} child {node {}}}
child {node {} child {node {}}};
\end{scope}\\
};

\end{tikzpicture}
\end{document}

• It seems that you not believed to my answer to your previous question. Nesting TikZ picture inside nodes (matrix is just composition of nodes) lead to unexpected result as you faced now. – Zarko Nov 10 '20 at 7:32
• I believe your previous answer. As I explained that I need to draw a Hasse diagram of a poset, so it would be better if there is another solution. Also I am interested in why this unexpected result happens. @Zarko – MMM Nov 10 '20 at 10:29
• @Zarko Nesting nodes within nodes, you mean? Also problematic, but not quite putting entire pictures inside them? Or did I misunderstand something? – cfr Dec 24 '20 at 3:44
• @cfr, hm, now I see two possibilities: (i) that my point is lost in translation, (ii) that I'm wrong with my claims :-). I wanted to point out that each tree is a TikZ picture which OP insert in nodes. This is, at least as I know, in the most of cases lead to unexpected result (as OP is faced with). – Zarko Dec 24 '20 at 3:57
• @cfr, maybe you're right. This question is repeated tex.stackexchange.com/questions/569997/…, for which I suggest to not insert trees in nodes which resulted in correct drawing of trees. With TikZ picture I meant a picture of a tree composed from nodes inside of scope. I'm sorry but it is to early for providing better description, I haven't quite woken up yet :-( – Zarko Dec 24 '20 at 4:28

I find that the problem seems to be related with positioning. There is a workaround as follows.

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}
[level distance = 10mm]

\node [matrix, label=left:{$T_1$}] (T1)
{
\begin{scope}
[every node/.style={draw, circle, inner sep=1pt, minimum size = 1mm}]
\node [grow=down] {}
child {node {} child {node {}}}
child {node {} child {node {}}}
child {node {} child {node {}}};
\end{scope}\\
};

\node [matrix, label=left:{$T_2$}, matrix anchor=west] at ($(T1.east) + (10mm,0)$) (T2)
{
\begin{scope}
[every node/.style={draw, circle, inner sep=1pt, minimum size = 1mm}]
\node {}
child {node {} child {node {}}}
child {node {} child {node {}}}
child {node {} child {node {}}};
\end{scope}\\
};

\end{tikzpicture}
\end{document}

• As Zarko says, this isn't a good idea. Even if it works, it could break suddenly and messily. Usually, such things break at the worst possible moments. Is there any reason to structure the diagram this way? Could you use a tree, for example? Or a single matrix to place the nodes and then join them afterwards? – cfr Dec 24 '20 at 3:48