我想在乳胶中绘制以下格子图:
我尝试使用以下 Tikz 代码绘制下图 ABGFH:
\[
\begin{tikzpicture}[node distance = 2cm, auto]
\node (a) {A};
\node (b) [above of=a, left of=a] {F};
\node (c) [above of=a] {H};
\node (d) [above of=a, right of=a] {B};
\node (e) [above of=a, node distance = 4cm] {G};
\draw[-] (a) to (b);
\draw[-] (a) to (d);
\draw[-] (b) to (e);
\draw[-] (d) to (e);
\draw[-] (a) to (c);
\draw[-] (c) to (e);
\end{tikzpicture}
\]
但它产生了下图:
但怎样绘制整个图表呢?
谢谢
编辑:
我得到了以下代码:
\[
\begin{tikzpicture}[node distance = 2cm, auto]
\node (a) {A};
\node (b) [above of=a, left of=a] {F};
\node (c) [above of=a] {H};
\node (d) [above of=a, right of=a] {B};
\node (e) [above of=a, node distance = 4cm] {G};
\node (f) [above of=b] {E};
\node (g) [above of=d] {C};
\node (h) [above of=f, right of=f] {D};
\draw[-] (h) to (f);
\draw[-] (h) to (g);
\draw[-] (h) to (e);
\draw[-] (a) to (b);
\draw[-] (a) to (d);
\draw[-] (b) to (e);
\draw[-] (d) to (e);
\draw[-] (a) to (c);
\draw[-] (c) to (e);
\draw[-] (f) to (b);
\draw[-] (g) to (d);
\end{tikzpicture}
\]
这很好地产生了预期的图表。
编辑2:
现在我想更进一步。我想绘制 4 个分支 (AB、AC、AD、AE),如下所示:
怎么做?我应该使用角度吗?
答案1
第二次编辑后,不清楚上面的其他节点在图像上显示的内容。我猜,现在您遵循以下内容:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,
positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 17mm and 17mm, on grid,
every node/.style = {circle, minimum size=1.2em, inner sep=0pt}
]
\node (a) {A};
\node (b) [above right=of a] {B};
\node (c) [above=of b] {C};
\node (d) [above left=of c] {D};
\node (e) [below left=of d] {E};
\node (f) [below=of e] {F};
\node (g) [right=of e] {G};
%
\node (h) at ($(f)!0.3333)!(b)$) {H};
\node (i) at ($(f)!0.6666)!(b)$) {I};
\draw (a) -- (b) -- (c) -- (d) -- (e) -- (f) -- (a)
(a) -- (h) -- (g) -- (d)
(a) -- (i) -- (g)
(f) -- (g) -- (b);
\end{tikzpicture}
\end{document}