Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use TikZ to create trees. Now I've to arrange four trees in a matrix like this:

Tree A Tree B
Tree C Tree D

I already tried the \matrix command. This works, but it leaves absolutely no space between the trees. I want to have the trees to be seperated by a space, in order to create arrows between the trees. Ideally the four trees are located in four boxes, which all have the same size and the same space between them.

Any suggestions?

Thanks.

Edit: This is what I've come up with:

\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}

Now it would be nice to have boxes around the trees and to have arrows between the boxes...

share|improve this question
    
It's always nice to provide a minimal, working example. You can add space between columns in the matrix with the column sep=<length> parameter for the matrix. Will that help? –  Torbjørn T. Jun 12 '11 at 14:22
    
... and row sep=<length> for the rows, which you probably figured out. –  Torbjørn T. Jun 12 '11 at 14:34
    
Thanks! I've added an example. –  Fred Jun 12 '11 at 14:40
add comment

2 Answers

up vote 3 down vote accepted

Instead of a matrix I used the at syntax to explicitly position the trees; then I used rectangles to draw the frames (basically one rectangle conveniently shifted to guarantee the same size for the boxes):

\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}

share|improve this answer
1  
It's amazing how hard this is to do without explicitly giving coordinates. –  Alan Munn Jun 12 '11 at 23:05
    
@Alan: Indeed. After struggling with the matrix approach for a while, I decided to go with explicit coordinates; less automatic but a lot easier. –  Gonzalo Medina Jun 12 '11 at 23:27
    
Thanks! Using coordinates seems to be the best way to do this... –  Fred Jun 13 '11 at 8:28
add comment

Here is another less 'manual' approach using a matrix as the awesome positioning library. It is not perfect (due to lack of time). It is left as an 'exercise' to figure out alignment and boxes.

Alternatively, you could create four matrices. This would make boxing and probably alignment trivial; however boxing would be hard as you'd want them to be evenly big.

\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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.