因此,我正在使用以下代码为我的论文制作一棵树。我找不到很多关于如何将一个孩子(“niveaus”)链接到两个父母(“软技能”和“硬技能”)的答案,所以我用这种方式解决了它(参见代码)。我的问题是节点“niveaus”必须与节点“profiel”和“competenties”处于同一高度。我该怎么做?
PS,我知道我的代码很糟糕,但是我对 LaTeX 还很陌生,而且以前从未使用过 Tikz。
\begin{tikzpicture}[
sibling distance=8em,level distance=10em, every node/.style={shape=rectangle,draw,align=center,rounded corners,}, ->, grow=right, edge from parent/.style={draw,-latex}
]
\node{profiel}
child {node {competenties}
child{node(sk){soft skills}
child{node[above right](n){niveaus}}
}
child{node(hs){hard skills}
child[missing] {
node(n) {niveaus}
}
}
};
\draw (hs) [-latex]-- (n);
\end{tikzpicture}
答案1
使用forest
包:
\documentclass[border=3mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
for tree = {
% nodes
draw,
rounded corners,
text depth=0.25ex,
% tree
grow=0,
anchor=east,
s sep=11mm,
% edges
edge={-Stealth},
}
[profiel
[competenties
[soft skills, name=sf]
[,coordinate,no edge [niveaus, name=n,no edge]]
[hard skills, name=hs]
]
]
\draw[-Stealth] (sf) edge (n)
(hs) edge (n);
\end{forest}
\end{document}
答案2
\begin{tikzpicture}[
sibling distance=8em,
level distance=10em,
every node/.style={
shape=rectangle,
draw,
align=center,
rounded corners,
},
grow=right,
edge from parent/.style={
draw,
-latex
}
]
\node{profiel}child {node {competenties}
child{node(sk){soft skills}
}child{node[xshift =3cm](n) {niveaus}edge from parent[draw=none]}
child{node(hs){hard skills}
}
};
\draw (hs) [-latex]-- (n);
\draw (sk) [-latex]-- (n);
\end{tikzpicture}