Trees and macros with tikz
- by Tsf
I am trying to build my trees using macros but I don't get the result I want. Here is a minimal example:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\newcommand{\LeafNode}[1]{%
child {node {#1}}
}
\newcommand{\InnerNode}[3]{%
child {node {#3}
#1
#2
}
}
\begin{document}
\begin{tikzpicture}
\node (A) {A}
\LeafNode{B}
\LeafNode{C}
;
\end{tikzpicture}%
\hspace{2cm}%
\begin{tikzpicture}
\node (A) {A}
\InnerNode{\LeafNode{D}}{\LeafNode{E}}{B}
\LeafNode{C}
;
\end{tikzpicture}
\end{document}
I expected this to produce two trees:
A A
/ \ / \
B C B C
/ \
D E
but I am getting:
A
|
A B
| |
B D
| |
C C
Am I missing something or there is no way to do it?
BTW, if I omit the label on my root node, I get a PGF error:
! Package pgf Error: No shape named is known.
-- Tsf