1

I just have a very philosophical(?) question. At this time i am well in drawing pictures with tikz. Now i have to make some tree-like diagramms and ask myself which "package" i should use for this? In the Tikz manual there is already some sort of mechanism for drawing trees. More, I often heard of the package forest but which have a complete different syntax. Does it make sense to put effort in getting to know "forest" or is it the same as using the tikz mechanism? I dont want to change all of my work later on so I try my best to figure out which option should be used.

So in simple words:
Forest >>>> Tikz?
or ist it just the personal preference that counts and both are great?

EDIT: I want to achieve a "tree" like this one

Is therefore tikz, qtree or forest the best option?

10
  • I am afraid that this question will be closed since it is opinion-based. Note however that forest is based on TikZ, so it is indeed not very different.
    – user121799
    Aug 8, 2018 at 23:45
  • 5
    @marmot I agree that this is opinion based, but if SRel modifies the question to ask for what are the differences, it could be made into a non-opinion based question. And IMO they are quite different. The base TikZ tree drawing syntax is terrible, and it does no automatic packing or separating of nodes. The forest input syntax is simple and it can do many things programmatically, which in the base methods are I'm sure possible, but by no means trivial.
    – Alan Munn
    Aug 8, 2018 at 23:51
  • @AlanMunn I agree, and I am not too good at closing questions either. (For all the reasons you mention you did not use forest here, right? Just kidding. ;-)
    – user121799
    Aug 8, 2018 at 23:53
  • 1
    @marmot Well I'm very orthodox: if it ain't a tree, don't use forest. :)
    – Alan Munn
    Aug 8, 2018 at 23:55
  • 2
    @AlanMunn It depends on the kind of tree, too. Maybe the istgame thing is easier for game-theory trees, though obviously less flexible. And the tree layout algorithms of TikZ might be nice, if your trees require that level of automation. Otherwise, if it is a tree in the graph-theory sense, Forest; otherwise TikZ.
    – cfr
    Aug 9, 2018 at 2:02

1 Answer 1

2

Why to restrict to TikZ-tree or forest? A simple matrix also solves the problem:

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{positioning, matrix}

\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes, nodes={align=center, text width=2.4cm},
    column sep=5mm, row sep=2mm] (A) {
&&&{Group 1\\ 300 Subjects}&{Treatment 1\\ Drug X 325 mg}& \\
&{600\\ Men}&{Random\\ Assignment} & & & Compare Drop in Temperature\\
&&&{Group 2\\ 300 Subjects}&{Treatment 2\\ Placebo}& \\
{1200\\ Subjects} & & & & &\\
&&&{Group 1\\ 300 Subjects}&{Treatment 1\\ Drug X 325 mg}& \\
&{600\\ Women}&{Random\\ Assignment} & & & Compare Drop in Temperature\\
&&&{Group 2\\ 300 Subjects}&{Treatment 2\\ Placebo}& \\
};

\draw[->] (A-4-1)--(A-2-2);
\draw[->] (A-2-2)--(A-2-3);
\draw[->] (A-2-3)--(A-1-4);
\draw[->] (A-1-4)--(A-1-5);
\draw[->] (A-1-5)--(A-2-6);

\draw[->] (A-2-3)--(A-3-4);
\draw[->] (A-3-4)--(A-3-5);
\draw[->] (A-3-5)--(A-2-6);

\draw[->] (A-4-1)--(A-6-2);
\draw[->] (A-6-2)--(A-6-3);
\draw[->] (A-6-3)--(A-5-4);
\draw[->] (A-5-4)--(A-5-5);
\draw[->] (A-5-5)--(A-6-6);

\draw[->] (A-6-3)--(A-7-4);
\draw[->] (A-7-4)--(A-7-5);
\draw[->] (A-7-5)--(A-6-6);

\node[draw, below right=of A.south west, anchor=north west, inner xsep=3mm] (B) {Assignment to block is not random};

\draw[<-] (A-4-1)--(A-4-1|-B.north);
\end{tikzpicture}
\end{document}

enter image description here

Update:

Just to show that forest is probably better for schemes more similar to trees. I'm not a forest expert, so it's not perfect: lower Placebo nodes are not equally aligned. I hope someone could help.

\documentclass{standalone} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{forest}

\begin{document}
\begin{forest}
[1200\\ Subjects, for tree={align=center, grow'=east}
    [600\\ Men
        [{Random\\ Assignment}
            [{Group 1\\ 300 Subjects}
                [{Treatment 1\\ Drug X 325 mg}
                    [,phantom]
                    [,phantom]
                    [Compare Drop\\ in Temperature, name=aux11]
                ]
            ]
            [{Group 2\\ 300 Subjects}
                [{Treatment 2\\ Placebo}, name=aux12
                ]
            ]
        ]
    ]
    [{600\\ Women}
        [{Random\\ Assignment}
            [{Group 1\\ 300 Subjects}
                [{Treatment 1\\ Drug X 325 mg}
                    [,phantom]
                    [,phantom]
                    [Compare Drop\\ in Temperature, name=aux21]
                ]
            ]
            [{Group 2\\ 300 Subjects}
                [{Treatment 2\\ Placebo}, name=aux22
                ]
            ]
        ]
    ]
]
\draw (aux11)--(aux12) (aux21)--(aux22);
\end{forest}
\end{document}

enter image description here

2
  • Thank you. I did nearly everything else before with a matrix to arrange nodes and just wanted to learn something new. But I see you are right, matrix seems the easiest solution for this
    – SRel
    Aug 9, 2018 at 12:23
  • 1
    @SRel It's the easiest solution in this particular case because its even simmetry, but a matrix won't solve all possibilites. But this case (which is not a tree) you could use forest (or tikz-tree) to build the tree part add two right nodes with tikz commands. Forest is worth to learn.
    – Ignasi
    Aug 9, 2018 at 12:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .