带有方程式和箭头的流程图

带有方程式和箭头的流程图

我对如何在带有连接框的上方/下方箭头的方程式的框之间绘制流程图感到困惑,例如参见下图。在此处输入图片描述

答案1

欢迎来到 TeX.SE!这个起点够了吗?(我的回答基于这个答案编辑:在代码中添加了解释。这不会让您免于浏览 pgfmanual,但可能会让您有所了解。第二次编辑:按照 J Leon V. 的评论将文本居中对齐,并做了一些其他外观上的改变。

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

在此处输入图片描述

相关内容