考虑以下代码,
\documentclass{beamer}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\tikzset{level 1/.style={level distance=26pt,sibling distance=10pt}}
\tikzset{every tree node/.style={font=\fontsize{9pt}{8}\selectfont}}
\tikzset{edge from parent/.style=
{draw,edge from parent path={([shift={(0pt,0pt)}]\tikzparentnode) -- (\tikzchildnode)}}}
\Tree [.$=$ [.$+$
]
[.$-$
]
]
\end{tikzpicture}
\end{frame}
\end{document}
我需要做哪些修改才能使边缘的起点和终点更靠近父母和孩子?
我曾尝试移动它,但没有作用。
答案1
后the comment
澄清所需的输出,我不知道如何使用tikz-qtree
,但我可以为您提供使用强大forest
包(树语法几乎相同,但现在您有了额外的自定义功能)。
For example, you can set the parent anchor to be `west` for the left children and `east` for the right children (of course, more elaborate settings can be used, including for example shiftings):
\documentclass{beamer}
\usepackage{forest}
\begin{document}
\begin{frame}
\centering
\begin{forest}
for tree={
s sep=20pt,
math content,
node options={inner xsep=3pt},
if n=1
{edge path={
\noexpand\path[\forestoption{edge}]
(!u.west) -- (.child anchor)\forestoption{edge label};
}
}
{ if n'=1
{edge path={
\noexpand\path[\forestoption{edge}]
(!u.east) -- (.child anchor)\forestoption{edge label};
}
}
{}
}
}
[{=}
[+
[\div
]
[\ast
]
]
[-
[-
]
[+
]
]
]
\end{forest}
\end{frame}
\end{document}
结果: