I would like to make this figure in LaTeX using tikz (the figure is from a book):
I really have no idea where to start and how to do it. Thank you for your help.
I would like to make this figure in LaTeX using tikz (the figure is from a book):
I really have no idea where to start and how to do it. Thank you for your help.
As always with TikZ, there are many, many ways to construct such a diagram. Here are two just with basic TikZ functionalities.
Both use two PGFFor loops but the first one uses a rotates coordinate system where down-right is the nth row and down-left is the kth column (see at (\k, -\n) specification). Though, this means the first value of the index needs to be evaluated as k + n + 1 which can be done with \inteval or the count key from PGFFor (see count = \knp from \np which means \knp counts up from n + 1 for each k).
The second diagram constructs the diagram with an untransformed coordinate system where the rows are horizontally but the k columns remain in down-left direction which required a calculation for the x value of the node placement: 2k − n.
The condition for when to draw an arrow from the previous row/column is now a bit more complicated as well as before.
The conditions are evaluated with the primitive TeX control sequence \ifnum…\fi which I don't like but they are the most straightforward tool in this case, especially in combination with \inteval since it allows integer calculation on-the-fly.
\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}
\foreachin https://tikz.dev/pgffor – MS-SPO Jan 02 '24 at 16:44