1

I have a homework assignment where I need to generate a PDF file containing a tree image using Python 3 and LaTeX's tikz package. It'd be really helpful if someone has a simple sample code.

I need to know how to create a child node.

from pylatex import (Document, TikZ, TikZNode, TikZDraw,TikZCoordinate,TikZUserPath, TikZOptions)

doc = Document()

# add our sample drawings
with doc.create(TikZ()) as pic:
    node_kwargs = {'align': 'center', 'shape' : 'circle','minimum size': '50pt', 'fill': 'black!20'}

    # create our test node
    box = TikZNode(text='My block',
                      handle='box',
                      options=TikZOptions('draw',
                                          'rounded corners',
                                          **node_kwargs))

    n_kw = {'shape' : 'circle',
                       'minimum size': '50pt',
                       'fill': 'black!20'}

#I DONT KNOW HOW TO PUT A CHILD NODE !!
    box.child =  TikZNode(text='My block 2',
                      handle='box2',
                      options=TikZOptions('draw',
                                          'rounded corners',
                                          **node_kwargs))


    pic.append(box)
    pic.append(box.child)

doc.generate_pdf('tikzdraw', clean_tex=False)
  • By tree, do you mean the plant, or the data structure? Additionally, take a look at the guidelines for [asking a homework question](https://meta.stackoverflow.com/a/334823/11384392). Stack Overflow is _not_ a code search engine, and you should be willing to put in some of your own effort to receive what you're looking for. – Das_Geek Jun 13 '19 at 18:13
  • Thank you for feedback, I will have your advice in mind. – Francisco Perez Lefiman Jun 14 '19 at 01:48

0 Answers0