
我嘗試使用 TikZ 繪製這樣的 wordnet
但我真的不知道該從什麼開始。有人可以幫我畫這個圖嗎?不幸的是,我沒有足夠的時間閱讀有關 TikZ 的書籍。這是我今天家庭任務的一部分:(
答案1
使用強大的可能性forest
包裹:
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
[entity
[inanimate-object
[natural-object
[geological-formation
[natural-elevation [hill], tikz={
\foreach \nodenam/\nodelabel in {!ul/0.000113,!u/0.000189}
\node[anchor=east,xshift=-10pt] at (\nodenam.west) {$\nodelabel$};
}
]
[shore [coast], tikz={
\foreach \nodename/\nodelabel in {!ul/0.0000216,!u/0.0000836,!uu/0.00176,!uuu/0.0163,!uuuu/0.167,!ur/0.365}
\node[anchor=west,xshift=10pt] at (\nodename.east) {$\nodelabel$};
}
]
]
]
]
]
\end{forest}
\end{document}
答案2
基於樹的解決方案
一種可能的解決方案是與和\usetikzlibrary{positioning}
結合使用。後兩者將允許您繪製樹結構,例如您所追求的樹,並且該庫將允許您根據其他節點定義節點,以便相對於單字放置數字。qtree
tikz-qtree
positioning
這是此類解決方案的 MWE:
\documentclass{article}
\usepackage{qtree}
\usepackage{tikz}
\usepackage{tikz-qtree,tikz-qtree-compat}
\tikzset{every tree node/.style={align=center, anchor=north}}
\usetikzlibrary{positioning}
\usepackage{fixltx2e}
\begin{document}
\begin{tikzpicture}[baseline]
\Tree
[.\node(entity){entity};
[.\node(inanimate){inanimate object};
[.\node(natural){natural object};
[.\node(geological){geological formation};
[.\node(naturalelev){natural elevation};
[.\node(hill){hill}; ]
]
[.\node(shore){shore};
[.\node(coast){coast}; ]
] ] ] ] ]
\node [base right=2cm of entity] (1) {0.395} ;
\node [base left=2.5cm of entity] (align) {};
\node [below=0.6cm of 1] (2) {0.167};
\node [below=0.6cm of 2] (3) {0.0163};
\node [below=0.55cm of 3] (4) {0.00176};
\node [below=0.6cm of 4] (5) {0.0000836};
\node [below=0.5cm of 5] (6) {0.0000216};
\node [below=3.8cm of align] (7) {0.000113};
\node [below=.5cm of 7] (8) {0.0000189};
\end{tikzpicture}
\end{document}
此解決方案的缺點是您必須手動放置額外定義的節點。有人可能會想到比我更優雅的解決方案,如果您必須製作許多這樣的圖表,這將特別好。儘管如此,這個解決方案至少似乎提供了您在這種情況下所追求的。
基於矩陣的解決方案
另一種解決方案可以避免上面直接提到的問題:即,每次必須繪製這些圖之一(或每次調整其中一個圖的大小)時都必須手動定義節點的問題是\usetikzlibrary{matrix}
.將所有資訊放置在矩陣的行和列中可以避免必須使用命令手動間隔資訊的問題\node
,因為這是根據儲存在矩陣的行和列中的資訊自動完成的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{figure}[h!]
\begin{tikzpicture}[description/.style={fill=white,inner sep=2pt}]
\matrix (m) [matrix of nodes, row sep=1.5em,
column sep=0.3em, text height=1.5ex, text depth=0.25ex]
{
& & entity & & 0.395 \\
& & inanimate object & & 0.167 \\
& & natural object & & 0.0163 \\
& & geological formation & & 0.00176 \\
0.000113 & natural elevation & & shore & 0.0000836 \\
0.0000189 & hill & & coast & 0.0000216 \\
};
\path[-] (m-1-3) edge (m-2-3)
(m-2-3) edge (m-3-3)
(m-3-3) edge (m-4-3)
(m-4-3) edge (m-5-2)
(m-5-2) edge (m-6-2)
(m-4-3) edge (m-5-4)
(m-5-4) edge (m-6-4);
\end{tikzpicture}
\end{figure}
\end{document}