更改 bayesnet 中 plate 对象的位置

更改 bayesnet 中 plate 对象的位置

我正在尝试将文字隔开$1 \le i \le m$,并$1 \le i' \le m'$在下图中使用bayesnet库创建,但它似乎总是将东西放在右下角,我现在知道如何让重叠的车牌格式化得很好,理想情况下$1 \le i \le m$是在其各自车牌的左下角。这是一个 MWE:

\documentclass[11pt]{report}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{figure}[!h]
    \centering
    \tikz{ %
        \node[obs] (y_idash) {$\by_{i i'}$} ; % 
        \node[latent, left=of y_idash] (u_i) {$\bu_i$} ; %
        \node[latent, right=of y_idash] (ud_i) {$\bu'_i$} ; %
        \plate[inner sep=0.35cm, xshift=-0.2cm, yshift=0.12cm] {plate1} {(u_i) (y_idash)} {$1 \le i \le m$}; %
        \plate[inner sep=0.35cm, xshift=-0.2cm, yshift=0.12cm] {plate2} {(ud_i) (y_idash)} {$1 \le i' \le m'$};
      \edge {u_i,ud_i} {y_idash} ; %
    }
\end{figure}
\end{document}
%note - compi[![enter image description here][1]][1]led with pdflatex

在此处输入图片描述

答案1

确实如此。这个库使用了弃用的语法和大量硬编码。从长远来看,我建议放弃它。目前,

\documentclass[11pt]{report}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{figure}[!h]
    \centering
    \tikz{ %
        \node[obs] (y_idash) {$\boldsymbol{y}_{i i'}$} ; % 
        \node[latent, left=of y_idash] (u_i) {$\boldsymbol{u}_i$} ; %
        \node[latent, right=of y_idash] (ud_i) {$\boldsymbol{u}'_i$} ; %
        \tikzset{plate caption/.style={caption, node distance=0, inner sep=0pt,
        below left=5pt and 0pt of #1.south,text height=1.2em,text depth=0.3em}}
        \plate[inner sep=0.35cm, xshift=0cm, yshift=0.12cm] {plate1} {(u_i) (y_idash)} {$1 \le i \le m$}; %
        \tikzset{plate caption/.style={caption, node distance=0, inner sep=0pt,
        below right=5pt and 0pt of #1.south,text height=1.2em,text depth=0.3em}}
        \plate[inner sep=0.35cm, xshift=0cm, yshift=0.12cm] {plate2} {(ud_i) (y_idash)} {$1 \le i' \le m'$};
      \edge {u_i,ud_i} {y_idash} ; %
    }
\end{figure}
\end{document}

在此处输入图片描述

如果您想要不使用这个库的解决方案,请告诉我。

这里尝试重做一些元素,这些元素是我厚颜无耻地从 bayesnet 库中偷来的,使用更现代的语法。它的工作方式是,有一种样式可以Bayes net在本地安装样式tikzpicture。因此,这将与其他库共存。我重做了一个命令,\edges可以说是更 TiZy方式,即通过insert path。结果:

\documentclass[11pt]{report}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit,arrows.meta,chains}
\tikzset{Bayes net/.code=\BayesTemp}
\edef\BayesTemp{\noexpand\tikzset{latent/.style={circle,fill=white,draw=black,inner sep=1pt,
minimum size=20pt,font=\noexpand\fontsize{10}{10}\noexpand\selectfont},
obs/.style={latent,fill=gray!25},
const/.style={rectangle, inner sep=0pt},
factor/.style={rectangle, fill=black,minimum size=5pt, inner sep=0pt},
det/.style={latent, diamond},
plate/.style={draw, rectangle, rounded corners, fit=##1},
wrap/.style={inner sep=0pt, fit=##1},
gate/.style={draw, rectangle, dashed, fit=##1},
caption/.style={font=\noexpand\footnotesize, node distance=0},
plate caption/.style={caption, node distance=0, inner sep=0pt,
below left=5pt and 0pt of ##1.south east},
every label/.append style={caption},
>={Triangle[]},
edges/.style args={from ##1 to ##2}{insert path={
foreach \noexpand\XX in {##1} { %
     foreach \noexpand\YY in {##2} { %
        (\noexpand\XX) edge (\noexpand\YY) }}
}}}} 
\begin{document}
\begin{figure}[!h]
    \centering
    \begin{tikzpicture}[Bayes net]
        \node[obs] (y_idash) {$\boldsymbol{y}_{i i'}$} ; 
        \node[latent, left=of y_idash,label={[name=ulab,text height=1.2em]below:$1 \le i \le m$}] (u_i) {$\boldsymbol{u}_i$} ; %
        \node[latent, right=of y_idash,label={[name=ulab',text height=1.2em]below:$1 \le i' \le m'$}] (ud_i) {$\boldsymbol{u}'_i$} ; %
        \draw[->,edges=from {u_i,ud_i} to {y_idash}];
        \node[plate=(u_i) (y_idash) (ulab)]{};
        \node[plate=(ud_i) (y_idash) (ulab')]{};
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

请注意,这根本不是对 bayesnet 库的抱怨。我确信在编写它时,这是一个巨大的进步。

相关内容