如何避免与节点框平行绘制的边的一部分?

如何避免与节点框平行绘制的边的一部分?

在下面的 MWE 中,蓝色节点边缘有一个水平部分,它与节点框相邻,在放大后可见。是否可以通过更改路径或锚点来避免这种情况?

Shawn 下面的解决方法是我尝试过的,但效果并不令人满意。有没有可能两全其美?

\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}

重复行

这是我尝试过的,但最终结果在审美上不达标,消费者宁愿接受原来的方案:

\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}

在此处输入图片描述

答案1

parent anchor不绘制移动

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

在此处输入图片描述

代码:

\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}

或者,您可以使用parent anchor=south west1em向右移动:

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          
    }
}{}

答案2

这是一个可能的解决方案,修改下面的行,在 (!uparent 锚点) 节点下方 2em 处添加一个额外的点。

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

在此处输入图片描述

代码

\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}

相关内容