# Draw a tree with variable node number

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}


-
Hello, my problem isn't TikZ, but that I have to specify the positions of the nodes. I would like to prefer definition as in tex.stackexchange.com/questions/34216/…, without specifying where to draw the nodes. But is it possible with variable node number? –  Bertram Nudelbach Jun 15 '12 at 16:13
It would be interesting that you give exactly the arguments necessary. –  Alain Matthes Jun 15 '12 at 16:23
I think tex would draw a much more beautiful tree than I would. So I would prefer to give the tree structure and get a perfect looking tree. –  Bertram Nudelbach Jun 15 '12 at 16:30
@BertramNudelbach I kind of feel where you are going with the question but if we (as human users) can not understand, I doubt that any automation script would understand what you want. Can you please give the requirements more clearly? I understand that you want to give a few ideas about the tree and you want to obtain exactly what kind of tree? You can provide hand sketches or some tree picture from online sources etc. about the end product. –  percusse Jun 15 '12 at 16:38
@percusse okay I see. I'm sorry for being so opaque :-) I'm making a presentation about the structure of a code. Basically it's nearly the same as the structure of the classDocument in Java. I would like to show that the document can contain 1..n elements. Each of these elements (lvl 1) contains an AtributeSet and 1..n elements. These elements (lvl 2) contain only a single AtributeSet. The tree shown above is simply all I want to have. Except some captions. –  Bertram Nudelbach Jun 15 '12 at 16:52

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}


-