可以用nicematrix宏包结合TikZ绘图实现:
\documentclass{ctexart}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}
\small
\NiceMatrixOptions{cell-space-top-limit=3pt}
$\begin{NiceArray}{*{9}{c}}[corners,hvlines]
\CodeBefore
\begin{tikzpicture}
\draw [fill=gray!35] (6-|1) |- (5-|2) |- (4-|3) |- (3-|4) |-
(2-|5) |- (3-|4) |- (4-|3) |- (5-|2) |- cycle ;
\draw [fill=gray!35] (6-|5) |- (5-|6) |- (4-|7) |- (3-|8) |-
(2-|9) |- (3-|8) |- (4-|7) |- (5-|6) |- cycle ;
\end{tikzpicture}
\Body
& & & & & & & & \\
& & & I_1 & I_2 & I_3 & I_4 & I_5 & \\
& & I_1 & I_2 & I_3 & I_4 & I_5 \\
& I_1 & I_2 & I_3 & I_4 & I_5 \\
I_1 & I_2 & I_3 & I_4 & I_5 \\
\CodeAfter
\begin{tikzpicture}
\draw [->] (6-|1) -- (1-|1);
\draw [->] (6-|1) -- (6-|last);
\draw [dashed] (2-|1) -- (2-|4);
\draw [dashed] (3-|1) -- (3-|3);
\draw [dashed] (4-|1) -- (4-|2);
\draw [dashed] (5-|7) -- (6-|7);
\draw [dashed] (4-|8) -- (6-|8);
\draw [dashed] (3-|9) -- (6-|9);
\draw [->] (2-|5) -- (1-|5);
\draw [->] (2-|6) -- (1-|6);
\draw [->] (2-|7) -- (1-|7);
\draw [->] (2-|8) -- (1-|8);
\foreach \t [count=\i from 1] in {0,...,8}
{
\node[yshift=-6pt] at (6-|\i) {\small$t_{\t}$};
}
\node[yshift=-6pt] at (6-|10) {\small$t$};
\foreach \p [count=\i from 2] in {{取指令},{译\hspace{\ccwd}码},
{执\hspace{\ccwd}行},{存结果}}
{
\node[xshift=-18pt] at (\i-|1) {\small\p};
}
\node[xshift=-5pt] at (1-|1) {\small$s$};
\draw [red ] (6-|1) |- (5-|2) |- (4-|3) |- (3-|4) |-
(2-|5) |- (3-|4) |- (4-|3) |- (5-|2) |- cycle ;
\draw [cyan] (6-|2) |- (5-|3) |- (4-|4) |- (3-|5) |-
(2-|6) |- (3-|5) |- (4-|4) |- (5-|3) |- cycle ;
\end{tikzpicture}
\end{NiceArray}$
\end{document}
其排版结果为:
说明,需要多次编译才能正确绘制。
谢谢了!