# Positioning equations with tikz diagram

I'm trying to annotate an diagram of a neural network with an equation that describes the activity of each node. I can't get the equation to the upper right, where I want it to be. I've tried using the scope environment in TikZ, \vspace and \hspace outside of tikz and even multicols.

I feel there likely is an easier or more elegant way of doing this. To make it easier to find, the equation I want to put in the upper right is, in this example, immediately after the tikzpicture environment ends. Here's my MWE:

 \documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\definecolor{burntorange}{RGB}{204,85,0}

\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]

\node[main node, scale=1.4] (interest) {$\vec{v}_i$};
\node[main node, fill=blue!10] (j) [below left of=interest] {$\vec{v}_j$};
\node[main node, fill=blue!10] (k) [below right of=j] {$\vec{v}_k$};
\node[main node, fill=burntorange, below right of=interest, distance = 5cm ]  (input) [below right of=interest] {input $u$};

\begin{scope}[every node/.style={font=\sffamily\small}]
\path
(interest)
edge [bend right] node[left] {$\mathbf{M}_{ji}$} (j)
edge [loop above] node[above] {$\mathbf{M}_{ii}$}  (interest)
edge [bend left] node {$\mathbf{M}_{ki}$} (k);
\path[every edge/.style={gray,draw=gray}]
(j)     edge node [right] {$\mathbf{M}_{ij}$} (interest)
edge [loop left] node {$\mathbf{M}_{jj}$} (j)
edge [bend right] node[left] {$\mathbf{M}_{jk}$} (k)
(k)     edge node [right] {$\mathbf{M}_{kj}$} (j)
edge node [bend right] {$\mathbf{M}_{ik}$} (interest)
edge [loop below] node {$\mathbf{M}_{kk}$} (k)
(input) edge [bend right] node {$\mathbf{W}_i$} (interest)
edge [bend left] node {$\mathbf{W}_k$} (k);
\end{scope}
\end{tikzpicture}
{$\tau_{i}\frac{d\vec{v_{i}}}{dt}=-\vec{v}_{i}+\mathbf{M}_{ii}\vec{v}_{i}+ \sum_{j\neq i}\mathbf{M}_{ij}\vec{v}_{j}+\mathbf{W}_{i}\vec{u}$}
\end{document}


I hope I understand your question corrcectly. You can put the equation in a node and position that node. Positioning can be in various ways left of v_i, above input u etc. Here is another alternative:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\definecolor{burntorange}{RGB}{204,85,0}
\begin{document}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]

\node[main node, scale=1.4] (interest) {$\vec{v}_i$};
\node[main node, fill=blue!10] (j) [below left of=interest] {$\vec{v}_j$};
\node[main node, fill=blue!10] (k) [below right of=j] {$\vec{v}_k$};
\node[main node, fill=burntorange, below right of=interest, distance = 5cm ]  (input) [below right of=interest] {input $u$};

\begin{scope}[every node/.style={font=\sffamily\small}]
\path
(interest)
edge [bend right] node[left] {$\mathbf{M}_{ji}$} (j)
edge [loop above] node[above] {$\mathbf{M}_{ii}$}  (interest)
edge [bend left] node {$\mathbf{M}_{ki}$} (k);
\path[every edge/.style={gray,draw=gray}]
(j)     edge node [right] {$\mathbf{M}_{ij}$} (interest)
edge [loop left] node {$\mathbf{M}_{jj}$} (j)
edge [bend right] node[left] {$\mathbf{M}_{jk}$} (k)
(k)     edge node [right] {$\mathbf{M}_{kj}$} (j)
edge node [bend right] {$\mathbf{M}_{ik}$} (interest)
edge [loop below] node {$\mathbf{M}_{kk}$} (k)
(input) edge [bend right] node {$\mathbf{W}_i$} (interest)
edge [bend left] node {$\mathbf{W}_k$} (k);
\end{scope}
\node at ([shift={(-1cm,-1cm)}]current bounding box.north east) {$\tau_{i}\frac{d\vec{v_{i}}}{dt}=-\vec{v}_{i}+\mathbf{M}_{ii}\vec{v}_{i}+ \sum_{j\neq i}\mathbf{M}_{ij}\vec{v}_{j}+\mathbf{W}_{i}\vec{u}$};

\end{tikzpicture}
\end{document}


• That's exactly what I wanted. I tried annotating edges, but it never occurred to me to use a node like that. Thank you for teaching me something about TikZ. – mac389 Sep 30 '12 at 14:45
• @mac389 My pleasure. If the math needs to be regular, you can add \displaystyle just after the first \$ sign which would show it as if it was enclosed by $...$ – percusse Sep 30 '12 at 14:47