我是 Latex 的初学者,对探索其广泛的功能非常感兴趣。我想建立一个家谱,并决定使用 Forest 包。我使用这个手册 -森林_doc。
我开始构建一棵有分叉边的树。我从第 4.2 节了解到,分叉边命令会修改父锚点和子锚点并设置必要的边路径。但我想要一个具有不同父锚点并经过手动校正的子锚点。我弄清楚了手动校正部分。但锚点,我无法覆盖。
这是我的代码:
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usepackage{xcolor}
\begin{document}
\begin{forest}
man/.style = {fill=blue!70},
woman/.style = {fill=green},
for tree={draw={black, thick}, edge = {draw, thick}, rounded corners, inner sep=5pt},
[Parent, man
[Wife, woman, for tree={grow=0} , before drawing tree={x+=5.5cm, y+=1cm}]
[Child, man, forked edges
[Grand Child, man]
[Grand Child, woman]
]
[Child, woman, forked edges
[Grand Child, man]
[Grand Child, man]
]
]
\end{forest}
\end{document}
结果如下:
我希望妻子节点的边缘从父母的东边开始,而不是从南边开始。请告诉我我应该给出什么选项。我尝试了父锚点和子锚点,但都没有用。提前谢谢!
答案1
我对 了解不多forest
,所以我不知道是否可行。似乎forked edges
将边缘锚点移动到一个点。一种可能性是先绘制no edge
它,然后再绘制它,如下所示:
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
man/.style = {fill=blue!70},
woman/.style = {fill=green},
for tree={draw={black, thick}, edge = {draw, thick}, rounded corners, inner sep=5pt},
[Parent, man,
[Wife, woman, for tree={grow=0} , before drawing tree={x+=5.5cm, y+=1cm}, no edge] {\draw[thick] () -- (!u);}
[Child, man, forked edges
[Grand Child, man]
[Grand Child, woman]
]
[Child, woman, forked edges
[Grand Child, man]
[Grand Child, man]
]
]
\end{forest}
\end{document}
编辑:
通过创建phantom
根,您可以使Parent
和Wife
子级处于同一级别,从而自动对齐它们,如下所示:
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
man/.style = {fill=blue!70},
woman/.style = {fill=green},
for tree={draw={black, thick}, edge = {draw, thick}, rounded corners, inner sep=5pt},
[,phantom[Parent, man
[Child, man, forked edges
[Grand Child, man]
[Grand Child, woman]
]
[Child, woman, forked edges
[Grand Child, man]
[Grand Child, man]
]
] [Wife, woman, no edge] {\draw[thick] () -- (!p);}]
\end{forest}
\end{document}
答案2
@hpekristiansen 第一个答案的细微变化:
\documentclass[border=3.141592]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
% common nodes style
draw,
thick,
rounded corners,
% styles
man/.style = {fill=cyan!30},
woman/.style = {fill=teal!30},
% tree
forked edge,
edge = {-, semithick},
}
[Parent, man, name=P
[Wife, woman, name=W, no edge,
for tree={grow=east, anchor=base},
before computing xy={l=-0mm,s=33mm},
]
[Child, man,
[Grand Child, man]
[Grand Child, woman]
]
[Child, woman,
[Grand Child, man]
[Grand Child, man]
]
]
\draw[semithick] (P) -- (W);
\end{forest}
\end{document}