我怎样才能将两个 bayesnet 对象放在一行中?

我怎样才能将两个 bayesnet 对象放在一行中?

我怎样才能将两个 bayesnet 对象放在一行中并用一个标题表示整体?

关于 tikzpicture 的帖子两张并排的 tikzpictures不起作用的意思是:

  1. 当我将 0.33 改为其他数字时,图片大小实际上是不可调的

  2. 两张图片垂直排列,而不是水平排列。

\begin{center}
\begin{tikzpicture}[scale=0.33] 
...
\end{tikzpicture}% pic 1
\qquad % <----------------- SPACE BETWEEN PICTURES
\begin{tikzpicture}[scale=0.33] 
...
\end{tikzpicture}% pic 2
\end{center}

MWE 按照评论中的要求:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.33]

\node[obs] (y11) {$Y_{11}$};
\node[obs, right = of y11] (y12) {$Y_{12}$};
\node[obs, right = of y12] (y13) {$Y_{13}$};
\node[latent, below = of y11] (mu1) {$\mu_1$};
\node[latent, right = of mu1] (mu2) {$\mu_2$};
\node[latent, right = of mu2] (mu3) {$\mu_3$};

\node[latent, right = of mu3] (sigma1) {$\sigma_1$};
\node[latent, right = of sigma1] (sigma2) {$\sigma_2$};
\node[latent, right = of sigma2] (sigma3) {$\sigma_3$};

\node[obs, below = of mu1] (y21) {$Y_{21}$};
\node[obs, right = of y21] (y22) {$Y_{22}$};
\node[obs, right = of y22] (y23) {$Y_{23}$};

\node[const, above = of sigma2] (beta) {$\beta$};

\edge {beta} {sigma1};
\edge {beta} {sigma2};
\edge {beta} {sigma3};

\edge {mu1} {mu2};
\edge {mu2} {mu3};
\edge {mu1} {y12};
\edge {mu2} {y13};
\edge {mu3} {y11};
\edge {mu1} {y22};
\edge {mu2} {y21};
\edge {mu3} {y23};

\edge {sigma1} {y12};
\edge {sigma2} {y13};
\edge {sigma3} {y11};
\edge {sigma1} {y22};
\edge {sigma2} {y21};
\edge {sigma3} {y23};

\end{tikzpicture}
~%
\begin{tikzpicture}[scale=0.33]

\node[factor] (n) {} {};
\node[obs, below = of n] (y) {$Y_i$};
\node[latent, above = of n] (sigma) {$\Sigma$};
\node[latent, left = of sigma] (mu) {$\vec\mu$};
\node[latent, right = of n] (f) {$f_i$}; 
\node[factor, above = of sigma] (exp) {} {};
\node[const, above = of exp] (beta) {$\beta$};
\plate {yf} {(y)(f)} {$n$};
\factoredge {mu} {n} {y};
\factoredge {sigma} {n} {y};
\factoredge {f} {n} {y};
\edge {beta} {sigma};

\end{tikzpicture}  
\end{center}
\end{document}

答案1

您只需添加transform shape。更新:我重新绘制了这个东西,因为它在和\plate下没有产生很好的输出。不幸的是,我的修复涉及一些距离的“硬编码”。也就是说,如果您进一步重新缩放,您需要调整,它们在这里是硬编码的。我有scaletransform shape7pt不是查看了包装手册,可能有更优雅的方法。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.85,transform shape]

\node[obs] (y11) {$Y_{11}$};
\node[obs, right = of y11] (y12) {$Y_{12}$};
\node[obs, right = of y12] (y13) {$Y_{13}$};
\node[latent, below = of y11] (mu1) {$\mu_1$};
\node[latent, right = of mu1] (mu2) {$\mu_2$};
\node[latent, right = of mu2] (mu3) {$\mu_3$};

\node[latent, right = of mu3] (sigma1) {$\sigma_1$};
\node[latent, right = of sigma1] (sigma2) {$\sigma_2$};
\node[latent, right = of sigma2] (sigma3) {$\sigma_3$};

\node[obs, below = of mu1] (y21) {$Y_{21}$};
\node[obs, right = of y21] (y22) {$Y_{22}$};
\node[obs, right = of y22] (y23) {$Y_{23}$};

\node[const, above = of sigma2] (beta) {$\beta$};

\edge {beta} {sigma1};
\edge {beta} {sigma2};
\edge {beta} {sigma3};

\edge {mu1} {mu2};
\edge {mu2} {mu3};
\edge {mu1} {y12};
\edge {mu2} {y13};
\edge {mu3} {y11};
\edge {mu1} {y22};
\edge {mu2} {y21};
\edge {mu3} {y23};

\edge {sigma1} {y12};
\edge {sigma2} {y13};
\edge {sigma3} {y11};
\edge {sigma1} {y22};
\edge {sigma2} {y21};
\edge {sigma3} {y23};

\end{tikzpicture}
\qquad%
\begin{tikzpicture}[scale=0.85,transform shape]
\node[factor] (n) {} {};
\node[obs, below = of n] (y) {$Y_i$};
\node[latent, above = of n] (sigma) {$\Sigma$};
\node[latent, left = of sigma] (mu) {$\vec\mu$};
\node[latent, right = of n] (f) {$f_i$}; 
\node[factor, above = of sigma] (exp) {} {};
\node[const, above = of exp] (beta) {$\beta$};
%\plate {yf} {(y)(f)} {$n$};
\node[inner sep=7pt,draw,rounded corners,fit=(f) (y),outer sep=0pt] (fit){};
\node[above=0pt of fit.-55]{$n$};
\factoredge {mu} {n} {y};
\factoredge {sigma} {n} {y};
\factoredge {f} {n} {y};
\edge {beta} {sigma};

\end{tikzpicture}  
\end{center}
\end{document}

在此处输入图片描述

答案2

缩放:

\documentclass{article}

 \usepackage{tikz}
 \usetikzlibrary{bayesnet}

\begin{document}

\begin{figure}
\scalebox{0.86}{%
\begin{tikzpicture}

\node[obs] (y11) {$Y_{11}$};
\node[obs, right = of y11] (y12) {$Y_{12}$};
\node[obs, right = of y12] (y13) {$Y_{13}$};
\node[latent, below = of y11] (mu1) {$\mu_1$};
\node[latent, right = of mu1] (mu2) {$\mu_2$};
\node[latent, right = of mu2] (mu3) {$\mu_3$};

\node[latent, right = of mu3] (sigma1) {$\sigma_1$};
\node[latent, right = of sigma1] (sigma2) {$\sigma_2$};
\node[latent, right = of sigma2] (sigma3) {$\sigma_3$};

\node[obs, below = of mu1] (y21) {$Y_{21}$};
\node[obs, right = of y21] (y22) {$Y_{22}$};
\node[obs, right = of y22] (y23) {$Y_{23}$};

\node[const, above = of sigma2] (beta) {$\beta$};

\edge {beta} {sigma1};
\edge {beta} {sigma2};
\edge {beta} {sigma3};

\edge {mu1} {mu2};
\edge {mu2} {mu3};
\edge {mu1} {y12};
\edge {mu2} {y13};
\edge {mu3} {y11};
\edge {mu1} {y22};
\edge {mu2} {y21};
\edge {mu3} {y23};

\edge {sigma1} {y12};
\edge {sigma2} {y13};
\edge {sigma3} {y11};
\edge {sigma1} {y22};
\edge {sigma2} {y21};
\edge {sigma3} {y23};

\end{tikzpicture}
\begin{tikzpicture}

\node[factor] (n) {} {};
\node[obs, below = of n] (y) {$Y_i$};
\node[latent, above = of n] (sigma) {$\Sigma$};
\node[latent, left = of sigma] (mu) {$\vec\mu$};
\node[latent, right = of n] (f) {$f_i$}; 
\node[factor, above = of sigma] (exp) {} {};
\node[const, above = of exp] (beta) {$\beta$};
\plate {yf} {(y)(f)} {$n$};
\factoredge {mu} {n} {y};
\factoredge {sigma} {n} {y};
\factoredge {f} {n} {y};
\edge {beta} {sigma};

\end{tikzpicture}}
\caption{text}
\end{figure}

\end{document}

相关内容