1

In the MWE below there is a horisontal portion of the blue nodes' edge, that is adjasent to the node box and visible at higher zoom. Is it possible to avoid that by changing a path or anchor?

Shawn below is a workaround I tried, but it was not pleasing. Would it be possible to get the best of both worlds?

\documentclass{standalone}
\usepackage{forest}

\begin{document}

\begin{forest} 
for tree={
    draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
    node options={font=\footnotesize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
    edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
    },
    where n children=0{
        child anchor=west,
        edge path={
            \noexpand\path[\forestoption{edge}]
            (!u.parent anchor) -- +(-6em,0) |- (.child anchor)\forestoption{edge label};
        },
        draw=red,for parent={
            parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue          
        }
    }{}
}
    [Parent,name=Parent
        [Child1,name=Child1
            [,phantom]
            [Child11]
            [Child12,name=Child12]
        ]
        [Child3
            [,phantom]
            [Child31,name=Child31]
            [Child32]
        ]
    ]
%
\end{forest}
\end{document}

Duplicate line

Here is what I tried, but the end result is aesthetically substandard, the consumer would rather live with the original:

\documentclass{standalone}
\usepackage{forest}

\begin{document}

\begin{forest} 
for tree={
    draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
    node options={font=\footnotesize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
    edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label}; % Removed a bend in the path and drew from the anchor down
    },
    where n children=0{
        child anchor=west,
        edge path={
            \noexpand\path[\forestoption{edge}]
            (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
        },
        draw=red,for parent={
            parent anchor=south west, l sep=-12em, grow'=east, calign=child edge, draw=blue % changed parent anchor to South-West       
        }
    }{}
}
    [Parent,name=Parent
        [Child1,name=Child1
            [,phantom]
            [Child11]
            [Child12,name=Child12]
        ]
        [Child3
            [,phantom]
            [Child31,name=Child31]
            [Child32]
        ]
    ]
%
\end{forest}
\end{document}

enter image description here

2 Answers 2

2

Shift the parent anchor without drawing

([xshift=-6em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};

enter image description here

Code:

\documentclass[margin=5mm]{standalone}
\usepackage{forest}

\begin{document}

\begin{forest} 
for tree={
    draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
    node options={font=\footnotesize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
    edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
    },
    where n children=0{
        child anchor=west,
        edge path={
            \noexpand\path[\forestoption{edge}]
            ([xshift=-6em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};
        },
        draw=red,for parent={
            parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue          
        }
    }{}
}
    [Parent,name=Parent
        [Child1,name=Child1
            [,phantom]
            [Child11]
            [Child12,name=Child12]
        ]
        [Child3
            [,phantom]
            [Child31,name=Child31]
            [Child32]
        ]
    ]
%
\end{forest}
\end{document}

Alternativly you can use parent anchor=south west and shift 1em to the right:

where n children=0{
    child anchor=west,
    edge path={
        \noexpand\path[\forestoption{edge}]
        ([xshift=1em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};
    },
    draw=red,for parent={
        parent anchor=south west, l sep=-12em, grow'=east, calign=child edge, draw=blue          
    }
}{}
1

This is one possible solution where the following line is modified, adding an extra point 2em down from the (!uparent anchor) node.

(!u.parent anchor) -- ([yshift=-2em]!u.parent anchor) -- +(-6em,0) |- (.child anchor)\forestoption{edge label};

enter image description here

Code

\documentclass{standalone}
\usepackage{forest}

\begin{document}

\begin{forest} 
for tree={
    draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
    node options={font=\footnotesize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
    edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
    },
    where n children=0{
        child anchor=west,
        edge path={
            \noexpand\path[\forestoption{edge}]
            (!u.parent anchor) -- ([yshift=-2em]!u.parent anchor) -- +(-6em,0) |- (.child anchor)\forestoption{edge label};
        },
        draw=red,for parent={
            parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue          
        }
    }{}
}
    [Parent,name=Parent
        [Child1,name=Child1
            [,phantom]
            [Child11]
            [Child12,name=Child12]
        ]
        [Child3
            [,phantom]
            [Child31,name=Child31]
            [Child32]
        ]
    ]
%
\end{forest}
\end{document}

You must log in to answer this question.

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