2

I'm trying to draw a tree with some text in the leaves that I'd like to rotate. The below code works fine except that the edges to the leaves are anchored to the right-hand side of the leaves rather than to the top.

\documentclass{article}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}

\begin{tikzpicture}
\tikzset{every leaf node/.style={font=\tiny,anchor=base west,rotate=-90}}
\tikzset{edge from parent/.style=
  {draw,
   edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
                          -| (\tikzchildnode)}}}
\Tree [.{$\rightarrow$} 
    [.{$\land$} 
        [.{$\circlearrowleft$} {$\tau$}  {CRP} ] 
        [.{$\rightarrow$} 
            [.{$\land$} 
                [.{$\circlearrowleft$} {$\tau$}  {Leucocytes} ] 
                [.{$\circlearrowleft$} {$\tau$}  {IV Antibiotics}  {IV Liquid}  {ER Registration}  {Admission IC}  {Admission NC}  {LacticAcid}  {ER Triage}  {ER Sepsis Triage} ]
            ] 
            [.{$\times$} {Release A}  {$\tau$} ]
        ]
    ] 
    [.{$\times$} {Release C}  {Release B}  
        [.{$\rightarrow$} 
            [.{$\times$} {Release E}  {Release D}  {$\tau$} ] 
            {Return ER} 
        ] 
        {$\tau$} 
    ]
]
\end{tikzpicture}

\end{document}

It renders as:

Wrong rendering

How to anchor the edges to the top of leaves?

Note that by changing

\tikzset{edge from parent/.style=
  {draw,
   edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
                          -| (\tikzchildnode)}}}

to

\tikzset{edge from parent/.style=
  {draw,
   edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
                          -| (\tikzchildnode.west)}}}

the edges between the intermediate nodes anchor to the left of the children nodes. This is undesired.

1 Answer 1

2

tikz-qtree is very inflexible, so we need an anchor point that works for both unrotated and rotated nodes. Instead of using .north for one and .west for the other, I use .north west for both and project it horizontal to align with .center - that is:

(\tikzchildnode.north west -| \tikzchildnode.center)

\documentclass[tikz, border=1 cm]{standalone}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\tikzset{every leaf node/.style={font=\tiny,anchor=base west,rotate=-90}}
\tikzset{edge from parent/.style=
  {draw,
   edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
                -|  (\tikzchildnode.north west -| \tikzchildnode.center)}}}
\Tree [.{$\rightarrow$} 
    [.{$\land$} 
        [.{$\circlearrowleft$} {$\tau$}  {CRP} ] 
        [.{$\rightarrow$} 
            [.{$\land$} 
                [.{$\circlearrowleft$} {$\tau$}  {Leucocytes} ] 
                [.{$\circlearrowleft$} {$\tau$}  {IV Antibiotics}  {IV Liquid}  {ER Registration}  {Admission IC}  {Admission NC}  {LacticAcid}  {ER Triage}  {ER Sepsis Triage} ]
            ] 
            [.{$\times$} {Release A}  {$\tau$} ]
        ]
    ] 
    [.{$\times$} {Release C}  {Release B}  
        [.{$\rightarrow$} 
            [.{$\times$} {Release E}  {Release D}  {$\tau$} ] 
            {Return ER} 
        ] 
        {$\tau$} 
    ]
]
\end{tikzpicture}
\end{document}

Three graph

1
  • Thank you, it works as expected. Can use please explain the modification?
    – tomash
    Commented Oct 13, 2021 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .