我使用 TikZ 创建树。现在我要将四棵树排列成矩阵,如下所示:
Tree A Tree B
Tree C Tree D
我已经尝试过 \matrix 命令。这个命令有效,但它在树之间完全没有留下任何空间。我想让树之间有一个空间,以便在树之间创建箭头。理想情况下,四棵树位于四个框中,所有框的大小和间距都相同。
有什么建议么?
谢谢。
编辑:这是我想到的:
\documentclass{article}
\usepackage{scalefnt}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{trees}
\usetikzlibrary{matrix}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{document}
\begin{tikzpicture}
[
every node/.style={rectangle, draw, fill=black!10,
text badly centered, font=\scalefont{0.45}, text width=1.3cm},
level distance=0.7cm,
level 1/.style={sibling distance=2cm}
]
\matrix [draw=none, fill=none, column sep=2cm, row sep=1.5cm]
{
\path node {Ressourcen} [edge from parent fork down]
child {node {Zeit}}
child {node {Umwelt}
child {node [text width=2.8cm]{Lernumgebung, Personen Material}}
}
child {node {Physiologie}};
&
\path node {Ziele} [edge from parent fork down]
child {node {kurzfristig}}
child {node {langfristig}};\\
\path node {Volition} [edge from parent fork down]
child {node {Aufmerksamkeit}}
child {node {Motivation}}
child {node {Emotionskontrolle}};
&
\node {Lernstrategien};\\
};
\end{tikzpicture}
\end{document}
现在,如果在树周围放置方框并在方框之间放置箭头,那就太好了……
答案1
我没有使用矩阵,而是使用at
语法来明确定位树;然后我使用矩形来绘制框架(基本上是一个矩形方便地移动以保证框的大小相同):
\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{scalefnt}
\usepackage{tikz}
\usetikzlibrary{trees,arrows,calc}
\begin{document}
\begin{tikzpicture}
[
every node/.style={rectangle, draw, fill=black!10,
text badly centered, font=\scalefont{0.45}, text width=1.3cm},
level distance=0.7cm,
level 1/.style={sibling distance=2cm}
]
\node at (0,0) (R) {Ressourcen} [edge from parent fork down]
child {node (Ze) {Zeit}}
child {node (U) {Umwelt}
child {node (L) [text width=2.8cm]{Lernumgebung, Personen Material}}
}
child {node (P) {Physiologie}};
\node at (7,0) (Zi) {Ziele} [edge from parent fork down]
child {node (k) {kurzfristig}}
child {node (l) {langfristig}};
\node at (0,-3.5) (V) {Volition} [edge from parent fork down]
child {node[text width=1.8cm] (A) {Aufmerksamkeit}}
child {node (M) {Motivation}}
child {node[text width=1.9cm] (E) {Emotionskontrolle}};
\node[text width=1.6cm] at (7,-3.5) (Le) {Lernstrategien};
\draw (-3.3,-2) rectangle (3.3,0.5);
\draw[xshift=7cm] (-3.3,-2) rectangle (3.3,0.5);
\draw[yshift=-3cm] (-3.3,-2) rectangle (3.3,0.5);
\draw[xshift=7cm,yshift=-3cm] (-3.3,-2) rectangle (3.3,0.5);
\draw[->] (3.3,-0.75) -- (3.7,-0.75);
\draw[->] (3.3,-3.75) -- (3.7,-3.75);
\end{tikzpicture}
\end{document}
答案2
这是另一种不太“手动”的方法,使用矩阵作为出色的positioning
库。它并不完美(由于时间不足)。它留作“练习”,以弄清楚对齐和框。
或者,您可以创建四个矩阵。这将使装箱和对齐变得微不足道;但是装箱会很困难,因为您希望它们大小均匀。
\documentclass[landscape]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,matrix}
\begin{document}
\begin{tikzpicture}[every node/.style={
draw,
fill=black!10,
text centered,
text width=2cm,
inner sep=5pt,
node distance=1em and 2ex
},
ghost/.style={draw=none, fill=none, text width=0em},
every matrix/.style={fill=none, inner sep=1em}]
\node[matrix, row sep=2em, column sep=2em] {
{
\node (r) {Ressourcen};
\node [below = of r] (u) {Umwelt};
\node [left = of u] (p) {Phyilogie} ;
\node [right = of u] (z) {Zeit};
\node [below = of u] (l) {Lernumgebung};
\foreach \i/\j in {r/p,r/z,r/u,u/l}
\draw[->] (\i.south) -|+ (0,-.5em) -| (\j.north);
};
&
{
\node (r) {Ressourcen};
\node [below = of r,ghost] (u) {};
\node [left = of u] (p) {Phyilogie} ;
\node [right = of u] (z) {Zeit};
\foreach \i/\j in {r/p,r/z}
\draw[->] (\i.south) -|+ (0,-.25em) -| (\j.north);
}\\
{
\node (r) {Ressourcen};
\node [below = of r] (u) {Umwelt};
\node [left = of u] (p) {Phyilogie} ;
\node [right = of u] (z) {Zeit};
\foreach \i/\j in {r/p,r/z,r/u}
\draw[->] (\i.south) -|+ (0,-.5em) -| (\j.north);
}
&
{
\node [below = of u] (l) {Lernumgebung};
}
\\
};
\end{tikzpicture}
\end{document}