我正在使用 tikz 库bayesnet
,但似乎无法弄清楚如何控制默认节点间距。我假设因为bayesnet
覆盖了默认节点样式。您可以在下面看到这一点:Tikz 节点响应node distance=5mm
配置选项,但节点样式latent
和obs
frombayesnet
忽略这一点,并且具有较大的间距:
\documentclass[13pt]{beamer}
\usetheme{Singapore}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{frame}{test}
\begin{tikzpicture}[node distance=5mm]
\node[circle] (a) {a};
\node[latent,circle,right=of a] (b) {b};%
\node[circle,right=of b] (c) {c};%
\node[obs,circle,right=of c] (d) {d};%
\edge {a} {b};
\edge {b} {c};
\edge {c} {d};
\end{tikzpicture}
\end{frame}
\end{document}
我希望有一种简单(整洁)的方法来控制使用 Tikz+bayesnet 时所有节点的默认间距?其他关于节点间距的问题似乎没有解决这个问题。
答案1
选项1您可以通过移动末端节点来缩短箭头(或参见选项 2)。
\documentclass[13pt]{beamer}
\usetheme{Singapore}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{frame}{test}
\begin{tikzpicture}[node distance=5mm]
\node[circle] (a) {a};
\node[latent,circle,right=of a] (b) {b};%
\node[circle,right=of b] (c) {c};%
\node[obs,circle,right=of c] (d) {d};%
\edge {a} {b};
\edge {b} {c};
\edge {c} {d};
\end{tikzpicture}
\begin{tikzpicture}[node distance=5mm]
\node[circle] (a) {a};
\node[latent,circle,right=of a, xshift=-0.5cm] (b) {b};% changed<<<<
\node[circle,right=of b] (c) {c};%
\node[obs,circle,right=of c, xshift=-0.5cm] (d) {d};%changed<<<<
\edge {a} {b};
\edge {b} {c};
\edge {c} {d};
\end{tikzpicture}
\end{frame}
\end{document}
选项 2latent
全局或局部 重新定义样式,改变node distance
样式obs
就会相应改变。
\tikzstyle{latent} = [circle,fill=white,draw=black,inner sep=1pt,
minimum size=20pt, font=\fontsize{10}{10}\selectfont, node distance=0.5]
,
\documentclass[13pt]{beamer}
\usetheme{Singapore}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{frame}{test}
\begin{tikzpicture}[node distance=5mm]
\node[circle] (a) {a};
\node[latent,circle,right=of a] (b) {b};%
\node[circle,right=of b] (c) {c};%
\node[obs,circle,right=of c] (d) {d};%
\edge {a} {b};
\edge {b} {c};
\edge {c} {d};
\end{tikzpicture}
\tikzstyle{latent} = [circle,fill=white,draw=black,inner sep=1pt,
minimum size=20pt, font=\fontsize{10}{10}\selectfont, node distance=0.5]
\begin{tikzpicture}[node distance=5mm]
\node[circle] (a) {a};
\node[latent,circle,right=of a] (b) {b};
\node[circle,right=of b] (c) {c};%
\node[obs,circle,right=of c] (d) {d};
\edge {a} {b};
\edge {b} {c};
\edge {c} {d};
\end{tikzpicture}
\end{frame}
\end{document}