2

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?

SRel
  • 1,313
  • 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. –  Aug 08 '18 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 08 '18 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. ;-) –  Aug 08 '18 at 23:53
  • 1
    @marmot Well I'm very orthodox: if it ain't a tree, don't use forest. :) – Alan Munn Aug 08 '18 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 09 '18 at 02:02
  • @OP Please edit your question into something people can answer here. (Unless you're happy to have it closed.) Please be a bit more specific about the kind of tree you need to draw, too, as some packages are only for special kinds of trees, while others are more general. – cfr Aug 09 '18 at 02:03
  • Okay I am fine with these comments. I see no function to mark this "question" as closed. How can I do that? But still that I can see this later on with having a look at the comments :) the tree should be some general tree, visualizing some sort of experimental methods like block matching. It's a tree which is even on each side, each level has elements. – SRel Aug 09 '18 at 03:09
  • I added an "answer" specifying the tree I want to achieve. Maybe the merge at the end could be problematic? However later I may want to create a much huge tree and therefore want to meant one package either forest or tikz or may qtree – SRel Aug 09 '18 at 04:02
  • The merge at the end requires some extra work but certainly can be done with forest or without. –  Aug 09 '18 at 04:28
  • That is not a tree in the relevant sense (and should be in your question - not in the answer space). Hence no tree-drawing package can draw it straightforwardly, although you can use a tree-drawing package to do the bit which is a tree. A tree has a single root and all its descendants have exactly one parent. That's the kind of tree forest, qtree, tikz-qtree etc. draw. – cfr Aug 09 '18 at 23:54

1 Answers1

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

Ignasi
  • 136,588
  • 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 09 '18 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 09 '18 at 12:40