1

For some reason, tikzset seems to draw pics differently the first and second time. In the following example, I expect the two neural networks I draw to be identical, with one directly right of the other:

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

Instead, the second box is shifted down as well as wider than the first box. enter image description here

Why is this?

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – hpekristiansen Sep 13 '21 at 15:29
  • Apologies, I've updated the code to be cut and paste compilable. – Steven Morad Sep 13 '21 at 15:58
  • 3
    see https://tex.stackexchange.com/a/302182/2388. The positioning key has side effects. – Ulrike Fischer Sep 13 '21 at 16:15

0 Answers0