答案1
与 TikZ 一样,有很多方法可以构建这样的图表。以下是两种仅具有基本 TikZ 功能的方法。
两者都使用了两个 PGFFor 循环,但第一个循环使用了旋转坐标系,其中右下角是n第行左下方是钾第列(见at (\k, -\n)
规范)。不过,这意味着索引的第一个值需要被评估为钾+n+ 1 可以使用\inteval
或count
PGFFor 中的键来完成(参见count = \knp from \np
这意味着\knp
从n每人 + 1钾)。
第二张图使用未变换的坐标系构建图表,其中行是水平的,但钾列保持在左下方向,这需要计算X节点放置的值:2钾−n。
从上一行/列绘制箭头的条件现在比以前更复杂一些。
\ifnum…\fi
这些条件是用我不喜欢的原始 TeX 控制序列来评估的,但在这种情况下,它们是最直接的工具,特别是与之结合使用时\inteval
,因为它允许即时进行整数计算。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, quotes}
\begin{document}
\tikzset{% settings common to both solutions
anchor=base, % nodes are aligned at their base
auto=right, % nodes along lines are placed to the right
% (all arrows are drawn reversed)
>={Stealth[round]}, % shorthand arrow tip
outer sep=+.1em, % lines connecting nodes are further away
every edge quotes/.append style={% quotes nodes are closer to the line
inner sep=+.15em, outer sep=auto}}
\tikz[x=(-45:1.5cm), y=(45:1.5cm)] % rotate and scale the coordinate system
\foreach[count/.list={\np from 1, \nm from -1}] \n in {0, ..., 5}
\foreach[count/.list={\kp from 1, \km from -1, \knp from \np}]
\k in {0, ..., \inteval{5-\n}}
\node (\k-\n) at (\k, -\n) {$A_{\knp, \k}$} % \knp = \inteval{\k+\n+1}
\ifnum\n=0
node[gray] at (\k, 1) {$k=\k$}
\fi
\ifnum\k=0
node[gray] at (-1, -\n-1) {$n=\np$}
\fi
\ifnum\inteval{\k*\n}>0
edge[<-, "$\cdot\kp$"] (\k -\nm)
edge[<-, "$\cdot\np$"] (\km-\n )
\fi;
\tikz[scale=1.5/sqrt 2] % same scale as in the previous diagram
\foreach[count/.list={\np from 2, \nm from 0}] \n in {1, ..., 6}
\foreach[count/.list={\kp from 1, \km from -1}] \k in {0, ..., \inteval{\n-1}}
\node (\k-\n) at (2*\k-\n,-\n) {$A_{\n, \k}$}
\ifnum\k=0
node[gray] at (-\n-2, -\n) {$n=\n$}
\fi
\ifnum\n=\inteval{\k+1}
node[gray] at (2*\k-\n+1, -\n+1) {$k=\k$}
\fi
\ifnum\n>2 \ifnum\k>0 \ifnum\k<\inteval{\n-1}
edge[<-, "$\cdot\kp$"] (\k -\nm)
edge[<-, "$\cdot\inteval{\n-\k}$"] (\km-\nm)
\fi\fi\fi;
\end{document}