4

I want to make a tree which has bulleted lists centered below the child nodes, like so:

tree image I want

I've searched on TeX SE and found questions which describe putting labels below nodes, but it doesn't quite work out for multiline text or lists. This is my MWE (it generates the pdf in TexStudio even though I get some residual errors):

\documentclass[11pt, letterpaper,twoside, fleqn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{forest}

\begin{document}
    \begin{figure}
        \begin{center}
            \begin{forest}
                for tree={
                    myleaf/.style={label=below:{\strut#1}},
                    s sep=5cm
                }
                [Root Question,rectangle,rounded corners,draw
                    [Yes,rectangle,rounded corners,draw,align=center,
                        myleaf={$\bullet$ Subsequent question?\\
                                $\bullet$ Subsequent longer\\
                                    question?}
                    ]
                    [No,rectangle,rounded corners,draw]
                ]
                \node[above=30pt,align=center,anchor=center] {Tree Title};
            \end{forest}
        \end{center}
        \label{fig_tree1}
    \end{figure}    
\end{document}

current bad mwe tree

I'm very new to Latex trees and I've been using forest so far, but I'm not opposed to a TikZ solution.


On an unrelated note, I would eventually also like to place two trees side-by-side in a single figure (as shown below, but with the "subsequent question" text slightly bigger). I could use some guidance on that too.

two trees side by side

4

You need to say align=left or something along these lines in order to allow for multi-line texts in a node. (A label is a node, too.)

\documentclass[11pt, letterpaper,twoside, fleqn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{forest}

\begin{document}
    \begin{figure}
        \begin{center}
            \begin{forest}
                for tree={
                    myleaf/.style={label={[align=left]below:{\strut#1}}},
                    s sep=5cm
                }
                [Root Question,rectangle,rounded corners,draw
                    [Yes,rectangle,rounded corners,draw,align=center,
                        myleaf={$\bullet$ Subsequent question?\\
                                $\bullet$ Subsequent longer\\
                                    question?}
                    ]
                    [No,rectangle,rounded corners,draw]
                ]
                \node[above=30pt,align=center,anchor=center] {Tree Title};
            \end{forest}
        \end{center}
        \label{fig_tree1}
    \end{figure}    
\end{document}

enter image description here

You could also use itemize if you specify the text width. This also addresses your second question, too.

\documentclass[11pt, letterpaper,twoside, fleqn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{forest}
\usetikzlibrary{positioning}
\tikzset{leaflet/.style={align=left,text width=3.14cm}}
\begin{document}
\begin{figure}[htb]
\floatsetup{valign=t, heightadjust=all}
\ffigbox{%
\begin{subfloatrow}
\ffigbox{\begin{forest}
                for tree={
                    s sep=3.14cm
                }
                [Root Question,rectangle,rounded corners,draw,alias=root
                    [Yes,rectangle,rounded corners,draw,alias=LL]
                    [No,rectangle,rounded corners,draw,alias=LR]
                ]
                \node[above=12pt of root,align=center,anchor=center] {LeftTree Title};
                \node[below=1pt of LL,leaflet]
                {\begin{itemize}\setlength\itemsep{0pt}
                                \item Subsequent question?
                                \item Subsequent longer
                                    question?
                                \end{itemize}};
                \node[below=1pt of LR,leaflet]
                {\begin{itemize}\setlength\itemsep{0pt}
                                \item Subsequent question?
                                \item Subsequent longer
                                    question?
                                \end{itemize}};                             
            \end{forest}}{\caption{Left.\label{fig:left}}}
\ffigbox{\begin{forest}
                for tree={
                    s sep=3.14cm
                }
                [Root Question,rectangle,rounded corners,draw,alias=root
                    [Yes,rectangle,rounded corners,draw,alias=RL]
                    [No,rectangle,rounded corners,draw,alias=RR]
                ]
                \node[above=12pt of root,align=center,anchor=center] {Right Tree Title};
                \node[below=1pt of RL,leaflet]
                {\begin{itemize}\setlength\itemsep{0pt}
                                \item Subsequent question?
                                \item Subsequent longer
                                    question?
                                \end{itemize}};
                \node[below=1pt of RR,leaflet]
                {\begin{itemize}\setlength\itemsep{0pt}
                                \item[{}] Hibernate?
                                \end{itemize}};                             
            \end{forest}}{\caption{Right.\label{fig:right}}}
\end{subfloatrow}}
{\caption{Trees.}\label{fig:Trees}}
\end{figure}
\end{document}

enter image description here

As you can see, things are now doubled: there is a title and a caption. I kept both as it may be easier to drop one of those than to add one.

  • Awesome thanks! If I use an itemize for the "Yes" list but only put a single word in the "No" list (without an itemize), how can I adjust the vertical alignment so that the first row of text under each node starts at the same height? (Currently the itemize environment adds some extra vertical spacing that doesn't occur with regular text) – takanuva15 Jan 16 at 3:35
  • @takanuva15 I guess there are three ways: (i) go as you originally did, i.e. add the bullets by hadn; (ii) find out what distance is added by itemize and add it to the below key; (iii) add an empty item. I chose (iii) for the above MWE. If you want to try (ii), you might use something like ` \node[below=1pt+1.33em of RR,leaflet] {Hibernate?}; ` but it is quite likely that this distance (1.33em) is not the perfect choice. – user121799 Jan 16 at 4:12
  • ...perfect! How can I get rid of the (a) and (b) under the trees (since I already have tree titles describing them)? I tried to get rid of the {\caption{...}} but that gave me an error with ffigbox. – takanuva15 Jan 16 at 15:23
  • @takanuva15 Are you sure you do not want \floatsetup{valign=t, heightadjust=all,style=Plaintop} instead? Then the captions would be on top, you could remove the separate titles, and refer to the subtrees. – user121799 Jan 16 at 15:31
  • Sure, that sounds good. (lol I realized that I can just google it and TeX SE will tell me to do \caption*{} for no captions. But yea, it makes more sense to just put the captions on top and make the caption be the "Tree Title".) Can you please update your code for what it would look like? – takanuva15 Jan 16 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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