Diagonal arrows (using TikZ) should be aligned in parallel
The fact that one can use \tikzmarknode
has already been pointed out by AndréC. The point of this is that there is no need to add all these arrows by hand, one can use loops. Also calc
is not needed here.
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{center}
\renewcommand*\arraystretch{1.3}
\begin{tabular}{c | ccccc}
$b_5$ & \tikzmarknode{11}{11} & & & & \\
$b_4$ & \tikzmarknode{7}{7} & \tikzmarknode{12}{12} & & & \\
$b_3$ & \tikzmarknode{4}{4} & \tikzmarknode{8}{8} & \tikzmarknode{13}{13} & & \\
$b_2$ & \tikzmarknode{2}{2} & \tikzmarknode{5}{5}& \tikzmarknode{9}{9} & \tikzmarknode{14}{14} & \\
$b_1$ & 1 & \tikzmarknode{3}{3} & \tikzmarknode{6}{6} & \tikzmarknode{10}{10} & \tikzmarknode{15}{15} \\
\hline
& $a_1$ & $a_2$ & $a_3$ & $a_4$ & $a_5$ \\
\end{tabular}
\end{center}
\begin{tikzpicture}[overlay, remember picture, shorten >=3pt, shorten <=3pt]
\foreach \X [count=\Y] in {3,6,10,15}
{\foreach \Z in {\the\numexpr\X-\Y,...,\the\numexpr\X-1}
{\draw [->] (\Z) -- (\the\numexpr\Z+1);} }
\end{tikzpicture}
\end{document}
However, IMHO one should not be forced to type the numbers. They can be filled in automatically, too. The point is that TikZ matrix element "knows" its position, it is stored in the counts \pgfmatrixcurrentrow
and \pgfmatrixcurrentcolumn
. Then we need only an ancient formula by Gauss to know the entries. If you want another matrix, just change the formula.
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{table}
\centering
\begin{tikzpicture}
\matrix[matrix of nodes,nodes in empty cells,column sep=1ex,row sep=1ex,
nodes={align=center,execute at begin node={
\ifnum\the\pgfmatrixcurrentcolumn>\the\pgfmatrixcurrentrow
\else
\pgfmathtruncatemacro{\effrow}{5-\pgfmatrixcurrentrow}%
\pgfmathtruncatemacro{\myres}{-\effrow+(\pgfmatrixcurrentcolumn+\effrow)*(\pgfmatrixcurrentcolumn+\effrow+1)/2}%
\myres%
\fi}}] (mat)
{& & & & & \\
& & & & & \\
& & & & & \\
& & & & & \\
& & & & & \\
};
\foreach \X in {1,...,5}
{\path ([xshift=-2pt]mat.west|-mat-\X-1) node[left] (b\the\numexpr6-\X) {$b_{\the\numexpr6-\X}$}
([yshift=-2pt]mat.south-|mat-5-\X) node[below] (a\X) {$a_{\X}$};
\ifnum\X>1
\foreach \Y in {1,...,\the\numexpr\X-1}
{\draw[-stealth,shorten >=-2pt,shorten <=-2pt] (mat-\the\numexpr\X-1\relax-\Y) -- (mat-\X-\the\numexpr\Y+1);}
\fi}
\draw (mat.north west) -- (a1.south-|mat.west) (mat.south east) -- (b5.west|-mat.south);
\end{tikzpicture}
\caption{A table.}
\label{tab:ABC}
\end{table}
\end{document}
The easiest thing in this code is to use the \tikzmarknode
command that creates a node
around each number and use these nodes as a reference.
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}%
\begin{document}
\begin{center}
\renewcommand*\arraystretch{1.3}
\begin{tabular}{c | ccccc}
$b_5$ & \tikzmarknode{11}{11} & & & & \\
$b_4$ & \tikzmarknode{7}{7} & \tikzmarknode{12}{12} & & & \\
$b_3$ & \tikzmarknode{4}{4} & \tikzmarknode{8}{8} & \tikzmarknode{13}{13} & & \\
$b_2$ & \tikzmarknode{2}{2} & \tikzmarknode{5}{5}& \tikzmarknode{9}{9} & \tikzmarknode{14}{14} & \\
$b_1$ & 1 & \tikzmarknode{3}{3} & \tikzmarknode{6}{6} & \tikzmarknode{10}{10} & \tikzmarknode{15}{15} \\
\hline
& $a_1$ & $a_2$ & $a_3$ & $a_4$ & $a_5$ \\
\end{tabular}
\end{center}
\begin{tikzpicture}[overlay, remember picture, shorten >=3pt, shorten <=3pt]
\draw [->] (2) -- (3);
\draw [->] (4) -- (5);
\draw [->] (5) -- (6);
\draw [->] (7) -- (8);
\draw [->] (8) -- (9);
\draw [->] (9) -- (10);
\draw [->] (11) -- (12);
\draw [->] (12) -- (13);
\draw [->] (13) -- (14);
\draw [->] (14) -- (15);
\end{tikzpicture}
\end{document}