我正在构建一个带标签的 tikzducks 树。MWE 将是
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{ducks}
\begin{document}
\begin{tikzpicture} [level distance=4cm, sibling distance=4cm]
\node {
\begin{tikzpicture}
\duck
\node [xshift=8, yshift=-25] at (wing) {Text};
\end{tikzpicture}
}
child { node {
\begin{tikzpicture}
\duck[signpost=1]
\node [xshift=8, yshift=-25] at (wing) {Text};
\end{tikzpicture}
} }
child { node {
\begin{tikzpicture}
\duck[graduate=gray!20!black, tassel=red!70!black]
\node [xshift=8, yshift=-25] at (wing) {Text};
\end{tikzpicture}
} };
\end{tikzpicture}
\end{document}
生成的图像是
现在,鸭子的高度不一样了(因为帽子),我想让它们的底部对齐,这样标签就水平了。我尝试过 y 轴移动鸭子,但没有成功
附加问题:我是否需要将标签从(翅膀)位置偏移,以及有没有更简单的方法可以将其放置在每只鸭子的正下方?
答案1
使用forest
包并不那么难:
编辑:上述假设并不完全正确。到目前为止,纠正森林节点中包含图像的问题非常困难。
编辑: 考虑@Ulrike Fischer 回答中的建议我的问题增加了鸭子尺寸的估计:
\documentclass[border=3.141592]{standalone}
\usepackage{forest}
\usetikzlibrary{ducks}
\begin{document}
\begin{forest}
for tree = {
minimum size = 6.2em, % approximation of a ducks sizes
/tikz/every label/.style = {label distance=0pt, inner sep=0pt},
% tree settings
anchor = south,
edge = {-, semithick, shorten < = 1em, shorten > = 0.5em},
s sep = 8mm,
l sep = 16mm,
}
[,tikz={\duck[shift=(.south west)]},
label=below:Text (label),
[,tikz={\duck[shift=(.south west),signpost=1]},
label=below:Text (label)] % processed
[,tikz={\duck[shift=(.south west),%
graduate=gray!20!black, tassel=red!70!black]},
,label=below:Text (label)]
]
\end{forest}
\end{document}
答案2
我找到了解决方案这里据我所知,绝对不应该嵌套tikzpicture
。
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{ducks}
\begin{document}
\begin{tikzpicture} [level distance=4cm, sibling distance=4cm,
hide/.style={opacity=0}]
\node[matrix] {
\duck[/tikz/local bounding box=d]
\path (d.south) node [below] {Text};\\
}
child { node[matrix] {
\duck[signpost=1,graduate=hide,tassel=hide,/tikz/local bounding box=d]
\path (d.south) node [below] {Text};\\
} }
child { node[matrix] {
\duck[graduate=gray!20!black, tassel=red!70!black,/tikz/local bounding box=d]
\path (d.south) node [below] {Text};\\
} };
\end{tikzpicture}
\end{document}