error on a tikz figure while doing wrap figure

Viewed 31
\usepackage{tikz}

\usepackage{listofitems} % for \readlist to create arrays

\tikzstyle{mynode}=[thick,draw=blue,fill=blue!20,circle,minimum size=22]

\begin{document}

\begin{wrapfigure}[l]

    \begin{tikzpicture}[x=2.0cm , y=1.5cm]

        \foreach \N [count=\lay,remember={\N as \Nprev (initially 0);}] in {4,5,5,5,3}{ % loop over layers

            \foreach \i [evaluate={\y=\N/2-\i; \x=\lay; \prev=int(\lay-1);}] in {1,...,\N}{ % loop over nodes

            \node[mynode] (N\lay-\i) at (\x,\y) {};

            \ifnum\Nprev>0 % connect to previous layer

            \foreach \j in {1,...,\Nprev}{ % loop over nodes in previous layer
 
            \draw[thick] (N\prev-\j) -- (N\lay-\i);}

                \fi
            }
        }
    \end{tikzpicture}
\end{wrapfigure}
\end{document}

It end ups having a compilation error on the \begin{tikzfugure} it says that there is an extra } which I don't see anywhere, you guys know what I'm doing wrong?

1 Answers

Two problems:

  • the syntax of warpfigure is wrong. It ought to be used like

    \begin{wrapfigure}[12]{r}[34pt]{5cm}
    

    Notice that it has two mandatory arguments. While you can leave off the optional arguments in [..], but you must not leave off the ones in {...}

  • \tikzstyle is deprecated. Use \tikzset instead


\documentclass{article}
\usepackage{wrapfig}

\usepackage{tikz}

\usepackage{listofitems} % for \readlist to create arrays

\tikzset{mynode/.style={thick,draw=blue,fill=blue!20,circle,minimum size=22}}

\usepackage{lipsum}

\begin{document}

\begin{wrapfigure}{l}{9cm}
    \begin{tikzpicture}[x=2.0cm , y=1.5cm]

        \foreach \N [count=\lay,remember={\N as \Nprev (initially 0);}] in {4,5,5,5,3}{ % loop over layers

            \foreach \i [evaluate={\y=\N/2-\i; \x=\lay; \prev=int(\lay-1);}] in {1,...,\N}{ % loop over nodes

            \node[mynode] (N\lay-\i) at (\x,\y) {};

            \ifnum\Nprev>0 % connect to previous layer

            \foreach \j in {1,...,\Nprev}{ % loop over nodes in previous layer
 
            \draw[thick] (N\prev-\j) -- (N\lay-\i);}

                \fi
            }
        }
    \end{tikzpicture}
\end{wrapfigure}
\lipsum
\end{document}

enter image description here

Related