1

How do I draw the tree diagram below in Latex? I also want to label the branches the way they are in the figure.

enter image description here

Here's my preamble:

\documentclass[11pt,reqno]{amsart}

% Packages
\usepackage{graphicx}
\usepackage{amssymb,amsthm}
\usepackage{amsmath}
\makeatletter
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
\newcommand*\widebar[1]{%
  \begingroup
  \def\mathaccent##1##2{%
    \rel@kern{0.8}%
    \overline{\rel@kern{-0.8}\macc@nucleus\rel@kern{0.2}}%
    \rel@kern{-0.2}%
  }%
  \macc@depth\@ne
  \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
  \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
  \macc@set@skewchar\relax
  \let\mathaccentV\macc@nested@a
  \macc@nested@a\relax111{#1}%
  \endgroup
}
\makeatother
\usepackage{cite}
%\usepackage{natbib}
%\bibpunct{(}{)}{;}{;}{,}{,}
\usepackage{xr-hyper}
\usepackage[
  colorlinks=true,
  citecolor=blue,
  urlcolor=blue,
  linkcolor=blue
]{hyperref}
\usepackage{bm}
\usepackage{fullpage}
\usepackage{ amssymb }
\usepackage{caption} 
\captionsetup{labelfont=normalfont,
              labelsep=colon}
\usepackage{mathabx}
\usepackage{subfig}
\makeatletter
\def\subsection{\@startsection{subsection}{1}%
  \z@{.5\linespacing\@plus.7\linespacing}{-.5em}%
  {\normalfont\itshape}}
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \edef\@toclevel{\ifnum#2=\@m 0\else\number#2\fi}%
  \ifnum #2>\c@secnumdepth \let\@secnumber\@empty
  \else \@xp\let\@xp\@secnumber\csname the#1\endcsname\fi
  \@tempskipa #5\relax
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \edef\@secnumpunct{%
      \ifdim\@tempskipa>\z@ % not a run-in section heading
        \@ifnotempty{#8}{.\@nx\enspace}%
      \else
        \@ifempty{#8}{.}{.\@nx\enspace}%
      \fi
    }%
    \@ifempty{#8}{%
      \ifnum #2=\tw@ \def\@secnumfont{\bfseries}\fi}{}%
    \protected@edef\@svsec{%
      \ifnum#2<\@m
        \@ifundefined{#1name}{}{%
          \ignorespaces\csname #1name\endcsname\space
        }%
      \fi
      \@seccntformat{#1}%
    }%
  \fi
  \ifdim \@tempskipa>\z@ % then this is not a run-in section heading
    \begingroup #6\relax
    \@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty\@M #8\par}%
    \endgroup
    \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
  \else
  \def\@svsechd{#6\hskip #3\@svsec
    \@ifnotempty{#8}{\ignorespaces#8\unskip
       %\@addpunct.
       }%
    \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
  }%
  \fi
  \global\@nobreaktrue
  \@xsect{#5}}
\makeatother

\pagestyle{plain}

\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{12pt}

\setcounter{secnumdepth}{2}

\allowdisplaybreaks[4]
% Commenting/debugging
\let\IG\iffalse
\let\ENDIG\fi

%% Shortcuts
\newcommand{\td}[2]{\dfrac{d #1}{d #2}}
\newcommand{\std}[2]{\dfrac{d^2 #1}{d {#2}^2}}
\newcommand{\ctd}[3]{\dfrac{d^2 #1}{d #2 d #3}}

\newcommand{\pd}[2]{\dfrac{\partial #1}{\partial #2}}
\newcommand{\spd}[2]{\dfrac{\partial^2 #1}{\partial {#2}^2}}
\newcommand{\cpd}[3]{\dfrac{\partial^2 #1}{\partial #2 \partial #3}}

\newcommand{\pdi}[2]{\partial #1/\partial #2}

\newcommand{\LR}{\Leftrightarrow}
\newcommand{\Lg}{\mathcal{L}}
\newcommand{\half}{\tfrac{1}{2}}
\newcommand{\eqp}{\phantom{=}}
\newcommand{\eqs}{\buildrel s \over =}
\newcommand{\me}{\mathrm{e}}
%begin codes for footnotes (symbols)
\makeatletter
\newcommand*{\myfnsymbolsingle}[1]{%
  \ensuremath{%
    \ifcase#1% 0
    \or % 1
      \dagger%   
    \or % 2
      1 
    \or % 3  
      2
    \or % 4   
      3
    \or % 5
      4
    \else % >= 6
      \@ctrerr  
    \fi
  }%   
}   
\makeatother

\newcommand*{\myfnsymbol}[1]{%
  \myfnsymbolsingle{\value{#1}}%
}

% remove upper boundary by multiplying the symbols if needed
\usepackage{alphalph}
\newalphalph{\myfnsymbolmult}[mult]{\myfnsymbolsingle}{}

\renewcommand*{\thefootnote}{%
  \myfnsymbolmult{\value{footnote}}%
}
%end codes for footnotes (symbols) 
5
  • 1
    Much of your code does not seem to be relevant to the question you're asking here. Please limit the example to only the code required for your issue to appear. You can have a look at this guide for how to prune your code for this purpose. Commented May 26, 2015 at 15:48
  • 1
    Also, see TeXample: Trees for similar diagrams. If you modify the one most similar to fill in your information as much as possible, you'll end up with a much simpler (and more likely to be answered) question. Commented May 26, 2015 at 15:50
  • @MikeRenfro Thanks for the link, but I was wondering how I should incorporate my codes within this document class: \documentclass[11pt,reqno]{amsart}.
    – OGC
    Commented May 26, 2015 at 16:26
  • You might want to look into tikz (see here).
    – phx
    Commented May 26, 2015 at 16:34
  • Is there a meaningful difference between amsart and other document classes for this case? Probably not. Same with your footnote symbols and other packages. The point is: try one of the examples linked above. See how close you can get it to your desired final result, and then ask about finishing up what's missing. What you've provided comes incredibly close to a "draw this for me" question, which may get answered, may not, or may draw a fair amount of criticism. Commented May 26, 2015 at 18:01

1 Answer 1

3

I can't read your handwriting well so I added placeholders in most nodes; if you could add them in your question, I'll update the answer.

I think you can easily use a forest package for this. If you want to add a label that follows the branch, then write:

edge label={node[midway,sloped,anchor=south]{some calc}}

Otherwise, remove sloped and replace the anchor with anchor=west if it goes to the right, or anchor=east if it goes to the left.


Edit: In order to add a caption place the figure between the tags \begin{figure} ... \end{figure}. Adding centering right after the first tag ensures the figure is properly centered.

After the figure but before the second tag, add \caption{} for your caption and then \label{} which must always be placed after the caption (for proper referencing and numbering), or at the very least inside the caption itself (see my code to see how). When you want to refer to the figure, just write the following in your regular text paragraph.

\cref{<label goes here>}

Usually it would be \ref{} but this one, along with the package cleveref adds the word fig. before the numbering.

One last thing: changing labels and references will need two compiles in a row for Latex to find/use the cross-references.

Output

figure 1

Code

\documentclass[a4paper]{article}
\usepackage{forest}
\usepackage{cleveref}

\usetikzlibrary{arrows.meta,shapes,positioning}
%
\tikzset{
    full/.style={circle,draw,inner sep=0, minimum size=1mm,fill=black},
    every node/.style={minimum height=5mm,font=\footnotesize}
}
%
\begin{document}
\begin{figure}
    \centering
\begin{forest} for tree={
        l=2cm,
        s sep=5mm
    }
%
[ ,name=root, full
    [ ,name=left, full, edge label={node[midway,sloped,anchor=south]{some calc}}
        [I can't read, name=bottomleft] ]
    [ ,name=right,full, edge label={node[midway,anchor=west]{$P+(d+)$}}
        [what you, edge label={node[midway,sloped,anchor=south]{some calc}}] 
        [wrote there, edge label={node[midway,anchor=west]{more calc}}] ] ]
%
\draw[dashed] (-2.2,0) -- (2.2,0) node[anchor=west,right] {$+ = 0$};
\draw[dashed] (-2.2,-2) -- (2.2,-2) node[anchor=west,right] {$+ = 1$};  
\node[anchor=east, left=5mm of bottomleft] {Really,};
\end{forest}
\caption{This is a caption\label{myforest}}
\end{figure}

I really enjoyed creating the forest in \cref{myforest}.
\end{document}
6
  • Thanks. How do I label the tree diagram as Figure 1? I tried using the caption command within the forest codes but it didn't work. I would also like to reference this Figure 1.
    – OGC
    Commented May 27, 2015 at 1:58
  • 1
    @user36829 Hey, I was asleep. See the edited answer, and let me know if something is not clear. :)
    – Alenanno
    Commented May 27, 2015 at 8:49
  • Is it possible to make this tree look a little bit fancy?
    – OGC
    Commented Jun 19, 2015 at 6:04
  • 1
    @user36829 It depends on what you mean by fancy. :P
    – Alenanno
    Commented Jun 19, 2015 at 9:01
  • Any cool templates that you could recommend?
    – OGC
    Commented Jul 2, 2015 at 17:16

You must log in to answer this question.

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