我正在使用 TikZ 在我的论文中绘制一些树。这是正在执行的操作的示例:
\documentclass{article}
\usepackage{tikz-qtree}
\newcommand{\Ta}{
\begin{tikzpicture}[level distance=30pt, sibling distance=90pt]
\node {}
child {node {$p(x)$}
child{node {$skipped$} edge from parent[draw=none]}
}
child {node {$s(x)$}
child {node {$\sim s(x)$}
child{node {$closed$} edge from parent[draw=none]}
}
};
\end{tikzpicture}
}
\newcommand{\Tb}{
\begin{tikzpicture}[level distance=30pt, sibling distance=90pt]
\tikzstyle{level 2}=[level distance=30pt, sibling distance=80pt]
\node {}
child {node {$p(x)$}
child{node {$q(x)$}
child{node {$skipped$} edge from parent[draw=none]}
}
child{node {$\sim p(x)$}
child{node {$closed$} edge from parent[draw=none]}
}
}
child {node {$s(x)$}
child {node {$\sim s(x)$}
child{node {$closed$} edge from parent[draw=none]}}
};
\end{tikzpicture}
}
\newcommand{\Tc}{
\begin{tikzpicture}[level distance=30pt, sibling distance=90pt]
\tikzstyle{level 1}=[sibling distance=90pt]
\tikzstyle{level 2}=[sibling distance=80pt]
\tikzstyle{level 3}=[sibling distance=40pt]
\node {}
child {node (n1) {$p(x)$}
child{node {$q(x)$}
child{node (n2) {$\sim p(x)$}
child{node {$closed$} edge from parent[draw=none]}
}
child{node {$\sim q(x)$}
child{node {$closed$} edge from parent[draw=none]}
}
child{node {$ r(x)$}
child{node {$skipped$} edge from parent[draw=none]}
}
}
child{node {$\sim p(x)$}
child{node {$closed$} edge from parent[draw=none]}
}
}
child {node {$s(x)$}
child {node {$\sim s(x)$}
child{node {$closed$} edge from parent[draw=none]}}
};
\path[dashed, <->](n1)edge [bend right=45] node[above left]{reduction}(n2);
\end{tikzpicture}
}
\begin{document}
\pgfversion
\begin{figure}
\centering
\begin{minipage}{0.45\textwidth}
\centering\Ta
\caption{$Ta$}
\end{minipage}
\begin{minipage}{0.45\textwidth}
\centering\Tb
\caption{$Tb$}
\end{minipage}
\vspace{15pt}
\vspace{15pt}
\begin{minipage}{0.45\textwidth}
\centering\Tc
\caption{$Tc$}
\end{minipage}
\end{figure}
\end{document}
有一个小问题我无法解决。命令:
\path[dashed,<->](n1)edge [bend right=45] node[above left]{reduction}(n2);
产生一条接触底部节点的线,这有点烦人。
我尝试了不同的方法,但似乎都没有效果。有人能帮我解决这个问题吗?
答案1
问题是由tikz-qtree
包引起的。如果您没有使用它的方法来输入树,则不应加载它。(制作最小工作示例的另一个原因。)
但是,由于tikz-qtree
绘制树的方式,您可能更喜欢树看起来是那样,在这种情况下,马丁的解决方案将解决问题。以下是同一棵树在tikz-qtree
加载和未加载时的比较:(加载的树在路径上tikz-qtree
使用解决方案。)shorten
没有tikz-qtree
和tikz-qtree
答案2
您可以使用shorten >=<length>
稍微缩短箭头:
\path[dashed,<->,shorten >=5pt](n1)edge [bend right=45] node[above left]{reduction}(n2);
shorten <
另一端也同样如此。