4

I am attempting to make a binary tree representation of a scheme expression. However, I noticed that I cannot repeat the word "cons" as a unique node. The tree will simply tie all subsequent nodes from the second cons to the first cons. I named them con and cons here to show how I want it to come out without naming the rest, to avoid showing the disaster that happens when I do.

\documentclass{article}
\newcommand\tab[1][1cm]{\hspace*{#1}}
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[margin=1.0in]{geometry}
\usepackage{courier}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,arrows.meta}
\usegdlibrary{trees}
\pagestyle{fancy}
\usepackage{amsmath}

\begin{document}
\begin{center}
\begin{tikzpicture}[>=Stealth]
\graph[binary tree layout]{
  con -- {   
    1 ,
   cons -- {
      l -- {
        m -- { n, o },
        p -- { q, r }
      }, 
      s -- {
        v -- {w, x},
        y -- {z}
      }
    }
  }
};
\end{tikzpicture}
\end{center}
\end{document}

binarytree

4

I'm not sure which nodes are supposed to contain cons and which not, so I made them all cons just to be on the safe side. Each unique node needs a unique name. But the content of the node need not be unique.

many cons

\RequirePackage{luatex85}
\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{courier}
\usetikzlibrary{graphs,graphdrawing,arrows.meta}
\usegdlibrary{trees}

\begin{document}
\begin{tikzpicture}[>=Stealth]
\graph[binary tree layout]{
  con/"cons" -- {
    1/"cons" ,
   cons -- {
      l/"cons" -- {
        m/"cons" -- { n/"cons", o/"cons" },
        p/"cons" -- { q/"cons", r /"cons"}
      },
      s/"cons" -- {
        v/"cons" -- {w/"cons", x/"cons"},
        y/"cons" -- {z/"cons"}
      }
    }
  }
};
\end{tikzpicture}
\end{document}
0

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.