Tikz text in Nodes

by Rik   Last Updated August 14, 2019 13:23 PM

I found the following code for the representation of a Neural Network in another thread:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows}
\begin{document}
    \begin{tikzpicture}[
    plain/.style={
       draw=none,
       circle,
       inner sep=2pt,
       font=\Huge,
       join = by -latex
      },
    net/.style={
      matrix of nodes,
      nodes={
        draw,
        circle,
        inner sep=10pt
        },
      nodes in empty cells,
      column sep=2cm,
      row sep=-9pt
      },
    >=latex
    ]
    \matrix[net] (mat)
    {
    |[plain]| \parbox{1.3cm}{\centering Input\\layer} & |[plain]|  \parbox{1.3cm}{\centering Hidden\\layer} & |[plain]| \parbox{1.3cm}{\centering Output\\layer} \\
    & |[plain]| \\
    |[plain]| & \\
    & |[plain]| \\
      |[plain]| & |[plain]| \\
    & & \\
      |[plain]| & |[plain]| \\
    & |[plain]| \\
      |[plain]| & \\
    & |[plain]| \\    };


    \foreach \ai [count=\mi ]in {2,4,...,10}
      \draw[<-] (mat-\ai-1) -- node[above] {Input \mi} +(-2cm,0);
    \foreach \ai in {2,4,...,10}
    {\foreach \aii in {3,6,9}
      \draw[->] (mat-\ai-1) -- (mat-\aii-2) ;
    }
    \foreach \ai in {3,6,9}
      \draw[->] (mat-\ai-2) -- (mat-6-3);
    \draw[->] (mat-6-3) -- node[above] {Output} +(2cm,0);

    \end{tikzpicture}
\end{document}

The picture looks as follows:

I was wondering whether it is possible to write text within the nodes themselves. For instance, in the first column of nodes, I would like to put $z_{1}$, $z_{2}$, etc..



Related Questions


Draw a node as a (perfect) square with Tikz

Updated March 21, 2016 08:09 AM

For each node I want to draw arrow '->'

Updated March 20, 2017 03:23 AM


Help drawing differents neural network architectures

Updated September 26, 2017 12:23 PM

Example of system architecture picture in TikZ

Updated July 10, 2018 09:23 AM