2

How can I put two bayesnet object in a row with one caption for the whole?

The post about tikzpicture Two tikzpictures side by side does not work in the sense that:

  1. picture size is in fact not adjustable when I change 0.33 to some other number

  2. two pictures lines up vertically, instead of horizontally.

\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 as requested in the comment:

\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}
8
  • 2
    Have you tried anything? A minimal working example for to start?
    – Sebastiano
    Commented Aug 8, 2018 at 22:15
  • @marmot this might be the case. But the image size is actually not changing, any suggestion?
    – ZHU
    Commented Aug 8, 2018 at 22:31
  • 2
    Can you please make a minimal working example (MWE)? Commented Aug 8, 2018 at 22:33
  • @samcarter included.
    – ZHU
    Commented Aug 8, 2018 at 22:34
  • 2
    @ZHU, this is not a MWE as requested by samcarter. W stands for working meaning it should be fully compilable with \documentclass ...
    – BambOo
    Commented Aug 8, 2018 at 22:36

2 Answers 2

3

You only need to add transform shape. Update: I redrew the \plate thingy since it did not yield a nice output under scale and transform shape. Unfortunately, my fix involved some "hard coding" of distances. That is, if you do further rescaling, you need to adjust the 7pt, which are hard coded here. I have not looked up the package manual, there could be more elegant ways.

\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}

enter image description here

4
  • My previous proposal was unnecessarily complicated and also the output was bad. Sorry for that! You can easily go up to scale=0.85 while having the figures side by side.
    – user121799
    Commented Aug 8, 2018 at 22:58
  • Thanks! Can you explain a bit more of what you did? Also, how to fix the graph on the right - either the factoredge of beta gets too close or in your example some part the graph separated from the plate.
    – ZHU
    Commented Aug 8, 2018 at 23:07
  • Also, what does 'hardcoded' mean in the case?
    – ZHU
    Commented Aug 8, 2018 at 23:20
  • @ZHU I made an update in which I fix the issue and do some hard coding myself to illustrate what it means. It just means that there are distances which are specified explicitly. As long as you do not rescale things, that is perfectly fine, but it can cause problems if you do want to rescale, as we see here.
    – user121799
    Commented Aug 8, 2018 at 23:35
1

Scale it:

\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}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .