1

I am confused about how to draw flow charts between boxes with equations above/below arrows connecting boxes, for example see the below picture.enter image description here

Mathmo
  • 23

1 Answers1

3

Welcome to TeX.SE! Is this starting point enough? (My answer is based on this answer.) EDIT: Added explanations in the code. This won't save you from glancing through the pgfmanual but may give you a start. 2nd EDIT: Followed J Leon V.'s comment to align the text in the center and made some other cosmetic changes.

\documentclass[tikz,border=3.14mm]{standalone}
% these are two of the main libraries for relative positioning (apart from matrix)
\usetikzlibrary{chains, positioning} 
\begin{document}
\begin{tikzpicture}[
  node distance = 2cm,
  start chain = main going right,
  box/.style = {draw, minimum height=7mm,text width=8mm,align=center,on chain,
  join=by {-latex,thick}}
  ]
  % put three nodes on a chain
  \node (n1)  [box]   at (0,0) {$\mathbf{x}_{t-1}$};
  \node (n2)  [box]   {$\mathbf{x}_{t}$};
  \node (n3)  [box]   {$\mathbf{x}_{t+1}$};
  % add two empty nodes left and right of the chain using positioning
  \node[minimum height=7mm,left=1.2cm of n1] (n0){};
  \node[minimum height=7mm,right=1.2cm of n3] (n4){};
  % draw arrows "by hand"
  \draw[thick,latex-] (n1) -- (n0);
  \draw[thick,latex-] (n4) -- (n3);
  % draw arrows in a loop
  \foreach \X[evaluate=\X as \Y using {int(\X-2)},evaluate=\Y as \SignY
  using {sign(\Y)},evaluate=\X as \LastX using {int(\X-1)}] in {1,2,3}
  {\ifnum\SignY=0
    \def\myt{t}
    \else
     \ifnum\SignY=1
      \def\myt{t+\Y}
     \else
     \def\myt{t\Y}
     \fi
   \fi
   \draw[thick,-latex] (n\X) -- ++(0,1) node[above](E\X){$\mathcal{E}_{\myt}$};
   \draw[latex-,shorten <=2pt] ([xshift=-2pt]n\X.north east) -- ++(0,0.5) node[midway,right,green!50!black]{$
   \frac{\partial\mathcal{E}_{\myt}}{\partial\mathbf{x}_{\myt}}$};
   \draw[thick,latex-] (n\X) -- ++(0,-1) node[below]{$u_{\myt}$};
  }
  % draw arrows by hand again
  \draw[-latex,shorten >=4pt,shorten <=4pt] ([yshift=4pt]n1.south west)
     -- ([yshift=4pt]n0.south east) 
     node[midway,below,text=red!50!black]{$\frac{\partial \mathbf{x}_{t-1}}{\partial
     \mathbf{x}_{t-2}}$};
  \draw[-latex,shorten >=4pt,shorten <=4pt] ([yshift=4pt]n2.south west)
     -- ([yshift=4pt]n1.south east) 
     node[midway,below,text=red!50!black]{$\frac{\partial \mathbf{x}_{t}}{\partial
     \mathbf{x}_{t-1}}$};
  \draw[-latex,shorten >=4pt,shorten <=4pt] ([yshift=4pt]n3.south west)
     -- ([yshift=4pt]n2.south east) 
     node[midway,below,text=red!50!black]{$\frac{\partial \mathbf{x}_{t+1}}{\partial
     \mathbf{x}_{t}}$};
  \draw[-latex,shorten >=4pt,shorten <=4pt] ([yshift=4pt]n4.south west)
     -- ([yshift=4pt]n3.south east) 
     node[midway,below,text=red!50!black]{$\frac{\partial \mathbf{x}_{t+2}}{\partial
     \mathbf{x}_{t+1}}$};
\end{tikzpicture}
\end{document}

enter image description here