Home > nodes > Draw a tree with variable node number

# Draw a tree with variable node number

June 15Hits:2

I would like to draw a tree in tex that is more like a sketch of a tree: It should contain variable node numbers.

Important is, that the dots are contained in the tree drawn. Is that possible with an automated command?

You see, since my painting skills are limitated I don't want to use TikZ and simply add the nodes this tree contains. I would like to say: Here is my structure, draw it for me. All I found is drawing trees with complete defined nodes.

EDIT

Without any style definitions here is a minimal example of what I thought about:

\documentclass{standalone}  \usepackage{tikz}  \begin{document} \tikzstyle{every node} = [rectangle,                 draw=black,                 fill=gray,                 text=black,                 text centered,                 rounded corners]      \begin{tikzpicture}         [sibling distance=8cm]      \node {Document}         child {             [sibling distance=2cm]             node (p1) {Paragraph}             child {                 node (e11) {Element}                 child {                     node {AttributeSet}                 }             }             child {                 node (e1n) {Element}                 child {                     node {AttributeSet}                 }             }             child {                 node {AttributeSet}             }         }         child {             [sibling distance=2cm]             [sibling distance=2cm]             [sibling distance=2cm]             node (pn) {Paragraph}             child {                 node (en1) {Element}                 child {                     node {AttributeSet}                 }             }             child {                 node (enn) {Element}                 child {                     node {AttributeSet}                 }             }             child {                 node {AttributeSet}             }         }     ;      \path[draw,dashed] (p1)--(pn);     \path[draw,dashed] (e11)--(e1n);     \path[draw,dashed] (en1)--(enn); \end{tikzpicture}  \end{document} 


I would prefer the dashed line to be just three/four dots.

Perhaps I don't understand the question...

Without TikZ but with pict2e; you need something to draw nice straight lines, here a code. If you want to automate the drawing, you can create some macros with dimensions for the arguments. It's easy to build a macro to place a circle and the label.

 \documentclass[11pt]{scrartcl}
\usepackage{pict2e,calc}
\newdimen\xlab
\newdimen\ylab
\newcommand*\Vertex[3]{%
\put(#1,#2){\circle*{5}}
\put(\numexpr #1 +5\relax,\numexpr #2 +5\relax){#3}
}

\begin{document}
\setlength\unitlength{2pt}%
\fbox{\begin{picture}(200,120)
\Vertex{100}{98}{A}
\put(90,75){\circle*{5}}
\put(90,75){\line(10,23){10}}
% \put(120,75){\circle*{5}}
\Vertex{120}{75}{B-N}
\put(120,75){\line(-20,23){20}}
\put(5,10){\circle*{5}}
\put(5,10){\line(85,65){85}}
\put(50,10){\circle*{5}}
\put(50,10){\line(40,65){40}}
\put(80,10){\circle*{5}}
\put(80,10){\line(10,65){10}}

\put(120,10){\circle*{5}}
\put(120,10){\line(0,65){65}}
\put(170,10){\circle*{5}}
\put(170,10){\line(-50,65){50}}
\put(190,10){\circle*{5}}
\put(190,10){\line(-70,65){70}}

\put(100,75){\dots}
\put(65,10){\dots}
\put(140,10){\dots}
%  \put(105,105){$A$}
\end{picture}}
\end{document}



forest can automatically handle the insertion and placement of ellipses as required. For example:

\documentclass[tikz, border=5pt]{standalone}
\usepackage{forest}

\begin{document}

\forestset{
gappy/.style={
before typesetting nodes={
insert after={
[\dots, no edge]
}
}
}
}
\tikzset{
document element/.style={
rounded corners,
draw,
inner color=gray!15,
outer color=gray!35,
}
}
\begin{forest}
for tree={
document element,
fit=band
},
before packing={
for tree={
if n children=3{
for children={
if n=2{calign with current}{}
}
}{}
}
}
[Document
[Paragraph, gappy
[Element, gappy
[Attribute Set]
]
[Element, before packing={calign with current}
[Attribute Set]
]
[Attribute Set]
]
[Paragraph
[Element, gappy
[Attribute Set]
]
[Element
[Attribute Set]
]
]
]
\end{forest}

\end{document}



Tags:nodes, trees

## Related Articles

• ### Draw a tree with variable node numberJune 15

I would like to draw a tree in tex that is more like a sketch of a tree: It should contain variable node numbers. Important is, that the dots are contained in the tree drawn. Is that possible with an automated command? You see, since my painting skil

• ### Drawing a tree where many nodes have the same child in TikZJune 8

I'm trying the draw a tree using the TikZ package, but I don't know how to draw a child node that has many parents. An example for that, is given by this picture My problem is how to draw the level 3. --------------Solutions------------- You can use

• ### How to draw a tree with fixed node distances? January 7

I would like to draw a picture that reflects some file structure. Below code works almost as expected. I need to adjust the connections between nodes so they don't start from the center of the bottom of the parent node but from near the left bottom c

• ### Draw Tikz Tree where level distance between multi-line nodes is constantMarch 26

I am drawing a tree with tikz, namely, using tikz-qtree-compat for simpler syntax. On the tree there can be nodes of different height but then branches become messy. I want to add an instruction where distance between the south point of a mother node

• ### Draw randomized tree in TikZAugust 16

I am trying to draw a randomized tree using TikZ, that is, I'm looking for a macro \randtree{NN}{x} that attaches a randomized tree of maximum depth x to a node named NN. The nodes need not be visible or marked, I just want the lines. I did a bit of

• ### Tree with some nodes and leafs in arbitrary places March 2

I need to draw a quite abstract tree. This tree will visualize proof substituting in natural deduction (proof theory). I have a deduction (let's call it 'D1') of A with open assumption B and a deduction (let's call it 'D2') of B with open assumption

• ### Drawing binary trees with LaTeX labelsSeptember 27

Is there some good tool for drawing binary trees with labels that are rendered by latex? I would need to have the tree node placement done automatically for me, because there are too many labels to calculate their placing manually. To be more specifi

• ### Drawing a tree diagramMay 26

How do I draw the tree diagram below in Latex? I also want to label the branches the way they are in the figure. Here's my preamble: \documentclass[11pt,reqno]{amsart} % Packages \usepackage{graphicx} \usepackage{amssymb,amsthm} \usepackage{amsmath}

• ### How can I draw simple trees in LaTeX?November 16

I need to draw a tree, and constantly using dotty and including the PNGs is starting to be a pain. Is there a way to get LaTeX to draw it's own trees that doesn't involve learning an entirely new language like TikZ? --------------Solutions-----------

• ### How do I draw a tree file structure?April 19

I'm looking for a (portable) software or script that would allow me to draw a specific file structure as a tree, in Windows XP. Much like DOS tree command, but "prettier" (as a graph or diagram) I already tried TreeSize but it doesn't suit my ne

• ### Aligning TikZ trees with other nodesApril 24

I would like to align a TikZ tree with another node by considering the tree as a whole like as if it was a node with anchors. For the moment I am only able to align the root node of the tree, not the whole tree itself. I use PGF 2.10. The following p

• ### Aligning multiple TikZ trees with other nodesMay 3

This question is directly related to Aligning TikZ trees with other nodes that I asked some time ago. By the time I asked the question I didn't realize that aligning multiple trees was not the same as aligning one tree. Indeed, the answer proposed by

• ### How to draw syntactical trees with parallel leafs for a natural language?May 6

I need to draw syntactical trees for a natural language. The problem is that I need all the leafs to be parallel. How the other nodes are sorted in relation to the other at the same depth is not important. In practical use you would a sentence at the

• ### How to draw the border of a node using late optionsMay 20

I want to create a series of rectangles, each with a different shade. The shade varies from white to black. I want to make the white (first) rectangle visible by drawing its border. My first step is to draw all the rectangles, without any conditional

• ### How to draw saturation symbol inside a node in TikZAugust 1

I'm working on a block diagram using TikZ. I'd like to create a symbol like below, which means I have to draw 5 lines inside a node and write a letter in the upper-right corner. What's the best way to achieve what I need? Any hints appreciated. -----

• ### Vertical line in binomial tree is ruining node coloringSeptember 9

How do I stop the dummy nodes from being colored? \documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix,fit,backgrounds,calc} \begin{document} \begin{tikzpicture}[>=stealth,sloped] \matrix (tree) [% matrix of nodes, minimum size=1cm, colum

• ### How can I improve my code for drawing a tree?December 22

This code draws a tree, but it's not in the functional style. tree[set_, m_] := Module[{θ, mz, my, temp, k, i, p1, p2, a, b, c, d, e, f}, θ = Pi/6; mz = {{Cos[θ], -Sin[θ]}, {Sin[θ], Cos[θ]}}; my = {{Cos[-θ], -Sin[-θ]}, {Sin[-θ], Cos[-θ]}}; temp = set

• ### Drawing a tree with text on the edge concisely using TikZJanuary 22

I am new to TikZ and am trying to draw a tree with text only on the edge (action/line). I have managed to do it as seen below but I was hoping there was a more concise/legible way. \documentclass{article} \usepackage{tikz} \usetikzlibrary{trees} \beg

• ### Overriding node draw style inherited from every node style messes up positioningMarch 5

I have been trying to draw a tree with TikZ. All nodes should be circles, so I use the every node style. There are some additional labels on some nodes, which have to be exceptions. I have tried this: \documentclass{article} \usepackage{tikz} \usetik

• ### How to draw dotted line between two nodesApril 11

\begin{tikzpicture} \tikzset{grow'=right,level distance=60 pt} \Tree [.I \edge node[auto=left]{M};[.II \edge node[auto=left]{L};$3,3$ \edge node[auto=right]{R};[.$x,0$ ]] \edge node[auto=left]{B};[.II \edge node[auto=left]{L};$0,0$ \edge node[auto=ri