虽然@cfr 为我的帖子提供了一个很好的解决方案这里,当我将代码插入主文档时,我遇到了问题,尽管它可以作为独立文档正常工作。它给出了错误:!\pgfmath@expression 定义中的参数编号非法,表明错误发生在 \end{forest}。虽然 forest 似乎更适合树形图,但我发现它非常困难。我需要一些时间才能解决 forest 包的问题。因此,我在 tikz 中重现了我的 mwe,只有树形图和我想要标签的位置(如我的代码中注释掉的那样)。
\documentclass[12pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[inner sep=1.5pt]
\node (10) {z}
child { node {x}
child { node {s}}
child { node {t}}}
child { node {y}
child { node {s}}
child { node {t}}}
;
% \node (from z to x) {$\frac{\partial z}{\partial x}$};
% \node (from z to y) {$\frac{\partial z}{\partial y}$};
% \node (from x to s) {$\frac{\partial x}{\partial s}$};
% \node (from x to t) {$\frac{\partial x}{\partial t}$};
% \node (from y to s) {$\frac{\partial y}{\partial s}$};
% \node (from y to t) {$\frac{\partial y}{\partial t}$};
\end{tikzpicture}
\end{document}
答案1
仅适用于 TikZ 的建议:
\documentclass[12pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[inner sep=1.5pt]
\node (10) {z}
[ auto,
sibling distance=2.4cm,
level distance=2cm,
level 2/.append style={
sibling distance=1.8cm,
level distance=1.5cm
},
edge from parent/.append style={nodes={pos=.6}}
]
child { node {x}
child { node {s}
edge from parent node[swap]{$\frac{\partial x}{\partial s}$}
}
child { node {t}
edge from parent node{$\frac{\partial x}{\partial t}$}
}
edge from parent node[swap]{$\frac{\partial z}{\partial x}$}
}
child { node {y}
child { node {s}
edge from parent node[swap]{$\frac{\partial y}{\partial s}$}
}
child { node {t}
edge from parent node{$\frac{\partial y}{\partial t}$}
}
edge from parent node{$\frac{\partial z}{\partial y}$}
}
;
\end{tikzpicture}
\end{document}