由于某种原因,tikzset
第一次和第二次绘制的图片似乎有所不同。在下面的例子中,我希望我绘制的两个神经网络是相同的,其中一个直接位于另一个的右侧:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\tikzset{
box/.style = {
draw,
minimum width=3em,
minimum height=3em
},
nn/.style = {
draw,
circle,
thick,
black,
inner sep=0pt,
text width=1mm,
},
edge/.style = {
-,
black,
semithick
},
mlp/.pic= {%
\node[nn] (n0) {};
\node[nn, below=0.2em of n0] (n1) {};
\node[nn, below=0.2em of n1] (n2) {};
\node[nn] (n3) at ([xshift=0.6em]$(n0)!0.5!(n1)$) {};
\node[nn] (n4) at ([xshift=0.6em]$(n1)!0.5!(n2)$) {};
\draw[edge] (n0.east) -- (n3.west);
\draw[edge] (n1.east) -- (n3.west);
\draw[edge] (n2.east) -- (n3.west);
\draw[edge] (n0.east) -- (n4.west);
\draw[edge] (n1.east) -- (n4.west);
\draw[edge] (n2.east) -- (n4.west);
\begin{scope}[on background layer]
\node[draw, fit=(n0) (n2) (n4), rounded corners=5pt, inner sep=2pt, thick] (box) {};
\end{scope}
},
}
\pic[](mlp0_){mlp};
\pic[right=of mlp0_box](mlp1_) {mlp};
\end{tikzpicture}
\end{document}
为什么是这样?