我想重新缩放贝叶斯网络 tikz 图。我的文档实际上是多列的,一列中有两个贝叶斯网络图,但我认为真正的问题是如何重新缩放此贝叶斯网络图:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\usetikzlibrary{arrows}
\usepackage{graphicx}
\usetikzlibrary{backgrounds}
\begin{document}
\tikz{
% nodes
\node[obs] (x) {$x$};%
\node[latent,above=of x,xshift=-1cm,path picture={\fill[gray!25] (path picture bounding box.south) rectangle (path picture bounding box.north west);}]
(y) {$y$}; %
\node[latent,above=of x,xshift=1cm] (z) {$z$}; %
% plate
\plate [inner sep=.25cm,yshift=.2cm] {plate1} {(x)(y)(z)} {$N$}; %
% edges
\edge {y,z} {x}
}
\end{document}
我怎样才能使整个图表变大/变小?
答案1
AndréC 的回答已经提到应该transform shape
以某种方式使用。但是,我不同意细节。我建议transform shape
在图片中添加一个整体,然后重新定义一种风格。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{tikzpicture}[scale=2.5,transform shape,wrap/.style={inner sep=0pt,
fit=#1,transform shape=false}]
% nodes
\node[obs] (x) {$x$};%
\node[latent,above=of x,xshift=-1cm,path picture={\fill[gray!25] (path picture bounding box.south) rectangle (path picture bounding box.north west);}]
(y) {$y$}; %
\node[latent,above=of x,xshift=1cm] (z) {$z$}; %
% plate
\plate[inner sep=.25cm,yshift=.2cm,transform shape=false]{plate1}{(x)(y)(z)}{$N$}; %
% edges
\edge {y,z} {x}
\end{tikzpicture}
\end{document}
请注意,这适用于您的代码。我没有广泛测试其他示例文档。在您的代码中,您也可以通过以下方式实现相同的效果
\renewcommand{\plate}[4][]{ %
\node[wrap=#3,transform shape=false] (#2-wrap) {}; %
\node[plate caption=#2-wrap] (#2-caption) {#4}; %
\node[plate=(#2-wrap)(#2-caption), #1,transform shape=false] (#2) {}; %
}
后
\usetikzlibrary{贝叶斯网络}
而且,正如您所看到的,我自由地删除了不必要的包和库。
答案2
默认情况下,节点对放大和缩小不敏感。为此,需要使用操作transform shape
(参见 TikZ 手册 3.0.1a 第 234 页)。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\usetikzlibrary{arrows}
\usepackage{graphicx}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[scale=1.5,every node/.style={transform shape}]
% nodes
\node[obs] (x) {$x$};%
\node[latent,above=of x,xshift=-1cm,path picture={\fill[gray!25] (path picture bounding box.south) rectangle (path picture bounding box.north west);}]
(y) {$y$}; %
\node[latent,above=of x,xshift=1cm] (z) {$z$}; %
% plate
\plate [inner sep=.25cm,yshift=.2cm] {plate1} {(x)(y)(z)} {$N$}; %
% edges
\edge {y,z} {x}
\end{tikzpicture}
\end{document}