# Construct an infinite tree with dots

Suppose at some point I want to replace nodes and edges by vertical dots if the tree is very big. Is there a possible way to do that with Tikz?

Latex code:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=8cm},
level 2/.style={sibling distance=4cm},
level 3/.style={sibling distance=2cm}]
\node {$\mathcal{P}({\mathcal{X}})$}
child {node {$\mathcal{P}_0({\mathcal{X}})$}
child {node {$\mathcal{P}_{0,1}({\mathcal{X}})$}
child {node {$S_1$}}
child {node {$S_2$}}
}
child {node {$\mathcal{P}_{0,\neg 1}({\mathcal{X}})$}
child {node {$S_3$}}
child {node {$\cdots$}}
}
}
child {node {$\mathcal{P}_{\neg 0}({\mathcal{X}})$}
child {node {$\mathcal{P}_{\neg 0,1}({\mathcal{X}})$}
child {node {$\cdots$}}
child {node {$\cdots$}}
}
child {node {$\mathcal{P}_{\neg 0,\neg 1}({\mathcal{X}})$}
child {node {$S_{k-1}$}}
child {node {$S_k$}}
}
};
\end{tikzpicture}

\end{document}


Output:

The goal is to replace the last level of the tree with vertical dots and the last level contains subsets ${S_1,\cdots, S_k}$.

The desired output:

• Are you open to a forest solution? Please can you make your code compilable? Presumably you can replace the content of the final nodes yourself?
– cfr
Commented Jun 15 at 14:38
• I think you can use e.g. edge from parent and set dotted.
– cfr
Commented Jun 15 at 14:42
• Thanks @cfr, I edited the code following your suggestions, but I don't know how to make a tree "infinite" with vertical dots Commented Jun 15 at 15:03
• To provide a complete example, can you add \documentclass, the packages needed to compile the picture and \begin{document} ... \end{document}? I know you don't know how to do the dots. I figured you probably would know how to do the dots inside the nodes, as opposed to the dots for edges.
– cfr
Commented Jun 15 at 15:05
• Are you aware that \vdots will give vertical dots? Commented Jun 15 at 15:14

Here is a possibility with forest. An option replace=<level> is defined. when this option is set, all levels below <level> are not drawn and the lowest remaining level has vertical dots below.

Here is the original tree:

And here is the exact same tree with option replace=2:

Or option replace=1:

\documentclass{article}

\usepackage{forest}

\forestset{replace/.style={if level=#1{label={[label distance=-2mm]south:\vdots}}{if level>=#1{phantom}{}}}}

\begin{document}

$\begin{forest} for tree={ math content, replace=2 } [\mathcal{P(X)} [\mathcal{P}_0(\mathcal{X}) [\mathcal{P}_{0,1}(\mathcal{X}) [\emptyset] [\{2\}] ] [\mathcal{P}_{0,\neg1}(\mathcal{X}) [\emptyset] [\{1\}] ] ] [\mathcal{P}_{\neg0}(\mathcal{X}) [\mathcal{P}_{\neg0,1}(\mathcal{X}) [\{2\}] [{\{0,2\}}] ] [\mathcal{P}_{\neg0,\neg1}(\mathcal{X}) [\{1\}] [{\{0,1\}}] ] ] ] \end{forest}$

\end{document}


Alternatively, you can replace the node contents with \vdots

using the following version of replace:

\documentclass{article}

\usepackage{forest}

\forestset{
replace/.style={if level=#1{delay={content={\vdots}}}{if level>=#1{phantom}{}}},
}

\begin{document}

$\begin{forest} for tree={ math content, s sep=1cm, replace=3 } [\mathcal{P(X)} [\mathcal{P}_0(\mathcal{X}) [\mathcal{P}_{0,1}(\mathcal{X}) [\emptyset] [\{2\}] ] [\mathcal{P}_{0,\neg1}(\mathcal{X}) [\emptyset] [\{1\}] ] ] [\mathcal{P}_{\neg0}(\mathcal{X}) [\mathcal{P}_{\neg0,1}(\mathcal{X}) [\{2\}] [{\{0,2\}}] ] [\mathcal{P}_{\neg0,\neg1}(\mathcal{X}) [\{1\}] [{\{0,1\}}] ] ] ] \end{forest}$

\end{document}

• Thanks +1 for the tip but I'm afraid my question wasn't clear, I don't want to replace the last level with vertical dots, I want to put vertical dots before the previous level of the tree. Commented Jun 15 at 19:36
• @Ayoubayjx: I updated my answer. Commented Jun 15 at 23:30
• Thanks, I really appreciate it. Sorry for the confusion I meant switching the last two levels: the last level contains the sets, and the level before that contains vertical dots. Commented Jun 15 at 23:59
• I think it would be helpful if you edited your question and provided a hand-drawn image of your desired result. Commented Jun 16 at 2:27
• I edited the question now, thanks! Commented Jun 16 at 13:25

I would reduce the horizontal length of the graphic adjusting the sibling distance parameters for the different levels in the tree. In this code, the sibling distance parameters for level 1, level 2, and level 3 have been reduced to 6 cm, 3 cm, and 1.5 cm respectively. Adjust these values further if you need an even more compact tree.

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=6cm},
level 2/.style={sibling distance=3cm},
level 3/.style={sibling distance=1.5cm}]
\node {$\mathcal{P}({\mathcal{X}})$}
child {node {$\mathcal{P}_0({\mathcal{X}})$}
child {node {$\mathcal{P}_{0,1}({\mathcal{X}})$}
child {node {$S_1$}}
child {node {$S_2$}}
}
child {node {$\mathcal{P}_{0,\neg 1}({\mathcal{X}})$}
child {node {$S_3$}}
child {node {$\vdots$}} % Vertical dots for omitted nodes
}
}
child {node {$\mathcal{P}_{\neg 0}({\mathcal{X}})$}
child {node {$\mathcal{P}_{\neg 0,1}({\mathcal{X}})$}
child {node {$\vdots$}} % Vertical dots for omitted nodes
child {node {$\vdots$}} % Vertical dots for omitted nodes
}
child {node {$\mathcal{P}_{\neg 0,\neg 1}({\mathcal{X}})$}
child {node {$S_{k-1}$}}
child {node {$S_k$}}
}
};
\end{tikzpicture}

\end{document}


• THank you for your answer. Actually, the desired output is shown in the edited question.* Commented Jun 16 at 13:26

The solution was easier then I thought, I just had to create 4 levels tree and use \ldots

\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=8cm},
level 2/.style={sibling distance=4cm},
level 3/.style={sibling distance=2cm},
level 4/.style={sibling distance=1cm}]

\node {$\mathcal{P}({\mathcal{X}})$}
child {node {$\mathcal{P}_0({\mathcal{X}})$}
child {node {$\mathcal{P}_{0,1}({\mathcal{X}})$}
child {node {$\vdots$}
child {node {$S_1$}}
child {node {$S_2$}}
}
child {node {$\vdots$}
child {node {$\ldots$}}
child {node {$\ldots$}}
}
}
child {node {$\mathcal{P}_{0,\neg 1}({\mathcal{X}})$}
child {node {$\vdots$}
child {node {$\ldots$}}
child {node {$\ldots$}}
}
child {node {$\vdots$}
child {node {$\ldots$}}
child {node {$\ldots$}}
}
}
}
child {node {$\mathcal{P}_{\neg 0}({\mathcal{X}})$}
child {node {$\mathcal{P}_{\neg 0,1}({\mathcal{X}})$}
child {node {$\vdots$}
child {node {$\ldots$}}
child {node {$\ldots$}}
}
child {node {$\vdots$}
child {node {$\ldots$}}
child {node {$\ldots$}}
}
}
child {node {$\mathcal{P}_{\neg 0,\neg 1}({\mathcal{X}})$}
child {node {$\vdots$}
child {node {$\ldots$}}
child {node {$\ldots$}}
}
child {node {$\vdots$}
child {node {$S_{k-1}$}}
child {node {$S_k$}}
}
}
};

\end{tikzpicture}


Result: