答案1
这是一个全自动的建筑。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\def\NM{5}
\matrix[matrix of nodes,column sep=1.5ex,row sep=1.5ex,
nodes in empty cells,
cells={nodes={
execute at begin node={%
\ifnum\the\pgfmatrixcurrentcolumn<\NM
\ifnum\the\pgfmatrixcurrentrow<\NM
$a_{\the\pgfmatrixcurrentrow\the\pgfmatrixcurrentcolumn}$
\fi
\else
\ifnum\the\pgfmatrixcurrentrow<\NM
$\cdots$
\else
$\ddots$
\fi
\fi
\ifnum\the\pgfmatrixcurrentrow=\NM
\ifnum\the\pgfmatrixcurrentcolumn<\NM
$\vdots$
\fi
\fi
}}},
execute at end matrix={%
\foreach \X in {2,...,\the\numexpr\NM-1\relax}
{
\ifodd\X
\draw[-latex] (\tikzmatrixname-\the\numexpr\X-1\relax-1)
--
(\tikzmatrixname-\X-1);
\else
\draw[-latex] (\tikzmatrixname-1-\the\numexpr\X-1\relax)
--
(\tikzmatrixname-1-\X);
\fi
\foreach \Y in {2,...,\X}
{\ifodd\X
\draw[latex-] (\tikzmatrixname-\the\numexpr1+\Y-2\relax-\the\numexpr\X-\Y+2\relax)
--
(\tikzmatrixname-\the\numexpr2+\Y-2\relax-\the\numexpr\X-\Y+1\relax);
\else
\draw[-latex] (\tikzmatrixname-\the\numexpr1+\Y-2\relax-\the\numexpr\X-\Y+2\relax)
--
(\tikzmatrixname-\the\numexpr2+\Y-2\relax-\the\numexpr\X-\Y+1\relax);
\fi}
}}]{
& & & & \\
& & & &\\
& & & &\\
& & & &\\
& & & &\\
};
\end{tikzpicture}
\end{document}