答案1
與 TikZ 一樣,有很多很多方法來建立這樣的圖表。這裡有兩個僅具有基本的 TikZ 功能。
兩者都使用兩個 PGFFor 循環,但第一個使用旋轉座標系,其中右下角是n第 行左下是kth 列(參見at (\k, -\n)
規範)。不過,這意味著索引的第一個值需要評估為k+n+ 1 可以使用PGFFor 中的\inteval
鍵來完成count
(查看count = \knp from \np
這意味著\knp
從n每個 + 1k)。
第二個圖使用未變換的座標系建立圖,其中行是水平的,但k列保持在左下方向,這需要計算X節點放置值:2k-n。
何時從上一行/列繪製箭頭的條件現在比以前更複雜一些。
這些條件是用原始的 TeX 控制序列來評估的\ifnum…\fi
,我不喜歡它,但在這種情況下它們是最簡單的工具,特別是與 結合使用,\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}