jluttine / tikz-bayesnet

TikZ library for drawing Bayesian networks, graphical models and (directed) factor graphs in LaTeX.
MIT License
829 stars 147 forks source link

Equal size nodes #10

Closed brandonjwk closed 6 years ago

brandonjwk commented 6 years ago

For a Bayesian network, is it possible to make all latent and obs nodes the same size in a tikzpicture? Most solutions suggest applying a minimum size to the style of the node, but then the node seems to lose its original properties.

jluttine commented 6 years ago

What original properties does the node lose? Could you provide some very simple code example and how you would like the end result to be different? I haven't used this package myself in a long time so I'm a bit rusty with this stuff and not sure if I'm able to help.

brandonjwk commented 6 years ago

I am not sure, but here is an MWE.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{bayesnet}

\begin{document}
The figure is supposed to look like this, but with the latent and obs nodes being the same size.
\begin{figure}[!h]
\centering
\begin{tikzpicture}
    \node[obs](L_m_t){$L_m^{(t)}$};
    \node[latent,below=of L_m_t,xshift=-2cm](L_t){$L^{(t)}$};
    \node[discr,above=of L_m_t,xshift=-2cm](S_L_t){$S_L^{(t)}$};
    \node[obs,right=of L_m_t,xshift=3cm](L_m_t1){$L_m^{(t+1)}$};
    \node[latent,right=of L_t,xshift=3cm](L_t1){$L^{(t+1)}$};
    \node[discr,right=of S_L_t,xshift=3cm](S_L_t1){$S_L^{(t+1)}$};
    \edge{L_t,S_L_t}{L_m_t};
    \edge{L_t1,S_L_t1}{L_m_t1};
    \edge{L_t}{L_t1};
    \edge{S_L_t}{S_L_t1};
\end{tikzpicture}
\end{figure}

However if I change the styles of the latent and observed nodes to a fixed minimum larger or the same size as the largest in the original figure, then I get this.

\begin{figure}[!h]
\centering
\begin{tikzpicture}[latent/.style={minimum size=2cm},obs/.style={minimum size=2cm}]
    \node[obs](L_m_t){$L_m^{(t)}$};
    \node[latent,below=of L_m_t,xshift=-2cm](L_t){$L^{(t)}$};
    \node[discr,above=of L_m_t,xshift=-2cm](S_L_t){$S_L^{(t)}$};
    \node[obs,right=of L_m_t,xshift=3cm](L_m_t1){$L_m^{(t+1)}$};
    \node[latent,right=of L_t,xshift=3cm](L_t1){$L^{(t+1)}$};
    \node[discr,right=of S_L_t,xshift=3cm](S_L_t1){$S_L^{(t+1)}$};
    \edge{L_t,S_L_t}{L_m_t};
    \edge{L_t1,S_L_t1}{L_m_t1};
    \edge{L_t}{L_t1};
    \edge{S_L_t}{S_L_t1};
\end{tikzpicture}
\end{figure}

\end{document}

And this is its output: test2.pdf

jluttine commented 6 years ago

Ok! The problem seems to be that you set the style, instead of modifying the existing style. Perhaps this helps: https://tex.stackexchange.com/questions/328377/tikz-add-options-to-existing-style

Would this work:

[latent/.append style={minimum size=2cm},obs/.append style={minimum size=2cm}]

Not sure if that's how it is used but perhaps the link I provided helps?

brandonjwk commented 6 years ago

Thanks for your help!!

It seems that setting: [latent/.append style={minimum size=2cm}] sets minimum sizes for all the node styles in the MWE and to control the minimum size for the discr node style separately I just added the append: [discr/.append style={minimum size=2cm}]

jluttine commented 6 years ago

Ok, great!