# Drawing pq-trees with all the numbers at the bottom

I need to draw PQ-trees in LaTeX.

Make all the numbers in the same level at the bottom like the figure above.

Thank you !

I put my existing latex code here:

\documentclass[tikz,convert=false]{minimal}
\usepackage{forest}
\usetikzlibrary{shapes.geometric,patterns}
\usetikzlibrary{arrows.meta, angles}
\forestset{
*|/.style={
parent anchor=south,
for descendants={
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor-|.child anchor) -- (.child anchor)\forestoption{edge label};
}
}
},
normal width/.initial=.5cm,
normal height/.initial=.3cm,
every forest node/.style={
draw,
minimum width=\pgfkeysvalueof{/forest/normal width},
minimum height=\pgfkeysvalueof{/forest/normal height},
inner sep=+0pt,
anchor=south,
},
rect/.style={
every forest node,
shape=rectangle,
minimum width=(#1)*(\pgfkeysvalueof{/forest/normal width})+(#1+1)*(\forestove{s sep})-(#1)*(\pgfkeysvalueof{/pgf/outer xsep}),
},
rect/.default=3,
ellipse/.style={
every forest node,
shape=ellipse,
minimum width=(#1)*(\pgfkeysvalueof{/forest/normal width})+(#1+1)*(\forestove{s sep})-(#1)*(\pgfkeysvalueof{/pgf/outer xsep}),
},
ellipse/.default=3,
patt/.style args={#1:#2}{
node options={
/tikz/path picture={
\pgfsetfillpattern{north east lines}{black}
\pgfpathrectanglecorners
{\pgfpointlineattime{#1}
{\pgfpointanchor{path picture bounding box}{north west}}
{\pgfpointanchor{path picture bounding box}{north east}}}
{\pgfpointlineattime{#2}
{\pgfpointanchor{path picture bounding box}{south west}}
{\pgfpointanchor{path picture bounding box}{south east}}}
\pgfusepath{fill}
}
}
},
patt/.default=0:1
}
\begin{document}
\begin{forest} for tree={child anchor=north}
[,ellipse=18,*|
[1]
[2]
[3]
[,ellipse=6,*|
[4]
[5]
[6]
[7]
[8]
[9]
]
[10]
[11]
[12]
[, ellipse=6 , *|
[13]
[14]
[15]
[16]
[17]
[18]
]
]
\end{forest}
\end{document}


The result of my code is like this:

The figure I expect is like this:

All the numbers are in the same level at the bottom even if there are more nodes.

It will be better if we can control the size of the nodes and numbers of the pq tree to make the figure more beautiful.Beautiful I don't think the size of my pq tree is very proper.

(After that I will try to generate it automatically everytime by python code myself)

Thank you!

• Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. May 9, 2017 at 12:53
• Welcome to TeX.SE! You mentioned you tried TikZ, can you show us what you have attempted/done, so that we don't have to start from scratch?
– Troy
May 9, 2017 at 14:26
• 2 is dead simple if you use Forest. I don't understand 1. What are the 'pointers' and why are they affected by any node's shape? There don't seem to be any circular nodes in the image anyway, so it isn't clear how relevant they are. Posting your existing TikZ code would help clarify things. I'm not entirely sure why the fork down style in TikZ isn't what you need, if you want to stay with plain TikZ for some reason.
– cfr
May 9, 2017 at 21:51
• @cfr Hello！The ellipse in my figure refers to circle(P_node). And I have edited my question. I have tried to use forest and put my code here.(I have solved the first question ,the vertical lines).But I don't know how to make all the numbers in the same level at the bottom(After I will generate the pq tree automatically) Thank you! May 11, 2017 at 6:57
• @cfr I have edited my question to make more clear May 11, 2017 at 20:40

Note that your .defaults are not doing anything and most of your definitions are never used. If you never plan to change normal width etc, then you are simply making computation much slower than required.

Do note that, if you borrowed the code from somebody else, courtesy (and, sometimes, licensing) requires you to attribute it and to provide a link, if possible. I could, obviously, be mistaken, but I guess the code isn't yours originally because what you haven't managed is much simpler than the code you've shown and the code you used does not seem to use the current version of Forest, which simplifies specifying an alternative edge path, for example.

If the code is on TeX SE, it would be especially useful to know where so that the post can be updated to use current Forest and amended to avoid the use of macros considered part of the internal implementation rather than the user interface.

As I understand it, you want something like this:

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shapes.geometric}
\forestset{
*|/.style={
parent anchor=children,
for descendants={
edge path'={
(!u.parent anchor-|.child anchor) -- (.child anchor)
}
}
},
normal width/.initial=.5cm,
normal height/.initial=.3cm,
ellipse/.style={
draw,
minimum width=\pgfkeysvalueof{/forest/normal width},
minimum height=\pgfkeysvalueof{/forest/normal height},
inner sep=+0pt,
anchor=children,
shape=ellipse,
minimum width=(#1)*(\pgfkeysvalueof{/forest/normal width})+(#1+1)*(\foresteoption{s sep})-(#1)*(\pgfkeysvalueof{/pgf/outer xsep}),
},
ellipse/.default=3,
}
\begin{document}
\begin{forest}
for tree={child anchor=parent},
where n children=0{tier=terminus}{},
[,ellipse=18,*|
[1]
[2]
[3]
[,ellipse=6,*|
[4]
[5]
[6]
[7]
[8]
[9]
]
[10]
[11]
[12]
[, ellipse=6 , *|
[13]
[14]
[15]
[16]
[17]
[18]
]
]
\end{forest}
\end{document}