2

I have nearly finished my code of latex. Here is my code.(code reference:Drawing pq-trees with all the numbers at the bottom)

\documentclass[tikz,convert=false]{standalone}
\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}),
  },
}
\begin{document}
\begin{forest} 
  [,rect=19,*|
    [1]
    [2]
    [3]
    [,rect=6,*|
    [4]
    [5]
    [6]
    [7]
     [,circle,draw,
    [13]
    [14]
    [15]
    [16]
    [17]
    [18]
    ]
    [8]
    [9]
    ]
    [10]
    [11]
    [12]
    [,circle,draw
    [13]
    [14]
    [15]
    [16]
    [17]
    [18]
    ]
    ]
\end{forest}
\end{document}

enter image description here

As you see, the problem is that the lines with circle is not normal. What I want now is to change all the lines connected to circles to obliques lines(just use the effect of package forest, to make the circles not be influenced by the setting for rectangles above).

For exemple like this: Here, all the lines to cirlces are oblique lines and all the lines to rectangles are vertical lines.

Thank you enter image description here

1
  • There's a reason my original code doesn't use \foreststove, which is that it is not intended to be part of the user interface. I'm not sure why you've used it rather than retrieving the value of the option in the standard way, as it makes your code less reliable.
    – cfr
    May 25 '17 at 13:19
1

In the style definition *|/.style, change the word descendants to children so that the change to the way edges are drawn only affects the children of the rectangular nodes and not all descendants.

adjusted edges

\foreststove should not be used in document code as it is considered internal and may, therefore, break in an update. That is, it isn't part of the user interface, which the package author tries hard to keep working when updating the package.

Tidying up a bit:

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{
  *|/.style={
    parent anchor=children,
    for children={
      edge path'={
        (!u.parent anchor-|.child anchor) -- (.child anchor)
      }
    }
  },
  declare dimen register=normal width,
  normal width'=.5cm,
  declare dimen register=normal height,
  normal height=.3cm,
  every forest node/.style={
    draw,
    minimum width/.register=normal width,
    minimum height/.register=normal height,
    inner sep=+0pt,
    anchor=children,
  },
  rect/.style={
    every forest node,
    shape=rectangle,
    tempdima={\pgfkeysvalueof{/pgf/outer xsep}},
    minimum width/.process={
      Rw+d nOw2+d Rw+d w3+d  {normal width}{##1*#1} {#1+1}{s sep}{##2*##1}  {tempdima}{##1*#1} {##1+##2-##3}
    },
  },
}
\begin{document}
\begin{forest}
  [,rect=19,*|
    [1]
    [2]
    [3]
    [,rect=6,*|
    [4]
    [5]
    [6]
    [7]
     [,circle,draw,
    [13]
    [14]
    [15]
    [16]
    [17]
    [18]
    ]
    [8]
    [9]
    ]
    [10]
    [11]
    [12]
    [,circle,draw
    [13]
    [14]
    [15]
    [16]
    [17]
    [18]
    ]
    ]
\end{forest}
\end{document}

yields the same output:

tidied code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.