
子節點在矩陣節點內的行為很奇怪。並且只出現在一個矩陣節點中。我知道在這個簡單的情況下有一些方法可以在沒有矩陣節點的情況下繪製它。但本質上我需要繪製部分有序集的哈斯圖,其中每個元素都是一棵樹。所以如果保留矩陣節點就好了。不管怎樣,奇怪的行為也很有趣。還可以檢查一下子節點奇怪地向右傾斜看到它在使用嵌套 tikzpicture 時也會出現。建議我針對矩陣節點的情況提出一個新問題。
\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}
答案1
庫positioning
的right = of …
隱式設定anchor = west
.不幸的是,這會傳遞到矩陣內的節點。
我們可以positioning
為矩陣創建額外的鍵來matrix anchor
代替,anchor
但在這種情況下,最簡單的解決方案是為矩陣的所有節點明確設定anchor = center
(預設)或centered
( 的別名)。anchor = center
TikZ 的樹語法非常簡單,不會自動設定任何錨點。
程式碼
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
level distance = 10mm,
every matrix/.style={
nodes={draw, circle, inner sep=1pt, minimum size = 1mm, centered}}]
\node [matrix, label=left:{$T_1$}] (T1){
\node {}
child {node {} child {node {}}}
child {node {} child {node {}}}
child {node {} child {node {}}};\\};
\node [matrix, right = of T1, label=left:{$T_2$}] (T2){
\node {}
child {node {} child {node {}}}
child {node {} child {node {}}}
child {node {} child {node {}}};\\};
\end{tikzpicture}
\end{document}
輸出
答案2
我發現問題似乎與positioning
.有一個解決方法如下。
\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}