我正在使用 TikZ 创建图表(它在 ConTeXt 中,但其思想在 LaTeX 中应该相同):
\usemodule[tikz]
\usetikzlibrary[graphs, graphdrawing]
\usegdlibrary[layered]
\defineframed[fixed][width=5mm,height=5mm, frame=off]
\starttext
\tikz \graph [layered layout, nodes={draw, circle}]
{
start__\fixed{$x_0$},
x1U__\fixed{$x_{1U}$},
x1M__\fixed{$x_{1M}$},
x1L__\fixed{$x_{1L}$},
x2U__\fixed{$x_{2U}$},
x2M__\fixed{$x_{2M}$},
x2L__\fixed{$x_{2L}$},
x3U__\fixed{$x_{3U}$},
x3M__\fixed{$x_{3M}$},
x3L__\fixed{$x_{3L}$},
start -> { x1U, x1M, x1L},
x1U -> { x2U, x2M, x2L},
x1M -> { x2U, x2M, x2L},
x1L -> { x2U, x2M, x2L},
x2U -> { x3U, x3M, x3L},
x2M -> { x3U, x3M, x3L},
x2L -> { x3U, x3M, x3L}
};
\stoptext
这使:
- 如何增加节点之间的距离?
- 如何使图表从左到右而不是从上到下增长?
我担心我会迷失在 TikZ 文档中。
答案1
有几个键可以让你控制节点之间的距离;在下面的代码中,我使用了sibling distance
和level sep
(还有node distance
);它们在第节中进行了描述27.3 填充和节点距离(CVS 版本的手册)。
要指定节点的邻居应该朝哪个方向增长,可以使用密钥grow
(还有其他几种可能性,使用第节中描述的一些其他密钥)。27.5 确定图形的方向)。
\usemodule[tikz]
\usetikzlibrary[graphs, graphdrawing]
\usegdlibrary[layered]
\defineframed[fixed][width=5mm,height=5mm, frame=off]
\starttext
\tikz \graph [layered layout, grow=right,sibling distance=3cm,level sep=2cm,nodes={draw, circle}]
{
start__\fixed{$x_0$},
x1U__\fixed{$x_{1U}$},
x1M__\fixed{$x_{1M}$},
x1L__\fixed{$x_{1L}$},
x2U__\fixed{$x_{2U}$},
x2M__\fixed{$x_{2M}$},
x2L__\fixed{$x_{2L}$},
x3U__\fixed{$x_{3U}$},
x3M__\fixed{$x_{3M}$},
x3L__\fixed{$x_{3L}$},
start -> { x1U, x1M, x1L},
x1U -> { x2U, x2M, x2L},
x1M -> { x2U, x2M, x2L},
x1L -> { x2U, x2M, x2L},
x2U -> { x3U, x3M, x3L},
x2M -> { x3U, x3M, x3L},
x2L -> { x3U, x3M, x3L}
};
\stoptext