Trees and Macros with Thix

I am trying to build my trees using macros, but I am not getting the result that 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 create two trees:

    AA
   / \ / \
  BCBC
               / \
              DE

but I get:

           A
           |
   Ab
   | |
   Bd
   | |
   CC

- ?

, node, PGF:

! Package pgf Error: No shape named  is known.

- Tsf

+3
2
+1

, LaTeX \newcommand. ,

\begin{tikzpicture}
 \node (A) {A}
    \LeafNode{B}
    \LeafNode{C}
 ;
\end{tikzpicture}

:

 \begin{tikzpicture}
 \node (A) {A}
   {child {node {B}}}
   {child {node {C}}}
 ;
\end{tikzpicture}

TikZ "" , .

, , .

+1

Source: https://habr.com/ru/post/1727401/


All Articles