答案1
NiceTabular
我碰巧有一个如何使用为特定坐标对着色的例子\CodeAfter
。
循环\foreach
用于evaluate=\x as \i using {int(\x+2)}
纠正由于表格的额外行和列而导致的坐标偏移,因此您只需在查看矩阵中的点时键入坐标即可。
第一张表格使用了我原来的彩色草图,第二张表格复制了您建议的设计。
MWE 如下。
\documentclass{article}
\usepackage{booktabs}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
\begin{NiceTabular}{p{2cm} ccc}
\diagbox{{\tiny road}}{{\tiny time}} & $t = 1$ & $t = 2$ & $t = 3$ \\
segment & $z_1$ & $z_2$ & $z_3$ \\
$r_1$ & $\circ$ & $\circ$ & $\circ$ \\
$r_2$ & $\circ$ & $\circ$ & $\circ$ \\
$r_3$ & $\circ$ & $\circ$ & $\circ$ \\
$r_4$ & $\circ$ & $\circ$ & $\circ$ \\
\vdots & \vdots & \vdots & \vdots \\
$r_{N_r}$ & $\circ$ & $\circ$ & $\circ$ \\
\CodeAfter
\begin{tikzpicture}[line width=3mm, opacity=0.5, line cap=round]
\foreach \x/\y/\c/\p/\q [
evaluate=\x as \i using {int(\x+2)}, evaluate=\y as \j using {int(\y+1)},
evaluate=\p as \u using {int(\p+2)}, evaluate=\q as \v using {int(\q+1)}] in
{1/1/blue/1/2, 1/1/blue/2/2, 2/1/red/1/2, 2/1/red/2/2, 3/1/green/1/2, 3/1/green/2/2,
1/2/yellow/1/3, 1/2/yellow/2/3, 2/2/orange/1/3, 2/2/orange/2/3}{
\draw [\c] (\i-\j.center) node[black]{$\bullet$} -- (\u-\v.center) node[black]{$\bullet$};
};
\end{tikzpicture}
\end{NiceTabular}
\begin{NiceTabular}{p{2cm} ccc}
\diagbox{{\tiny road}}{{\tiny time}} & $t = 1$ & $t = 2$ & $t = 3$ \\
segment & $z_1$ & $z_2$ & $z_3$ \\
$r_1$ & $\circ$ & $\circ$ & $\circ$ \\
$r_2$ & $\circ$ & $\circ$ & $\circ$ \\
$r_3$ & $\circ$ & $\circ$ & $\circ$ \\
$r_4$ & $\circ$ & $\circ$ & $\circ$ \\
\vdots & \vdots & \vdots & \vdots \\
$r_{N_r}$ & $\circ$ & $\circ$ & $\circ$ \\
\CodeAfter
\begin{tikzpicture}[very thick]
\foreach \x/\y/\p/\q [
evaluate=\x as \i using {int(\x+2)}, evaluate=\y as \j using {int(\y+1)},
evaluate=\p as \u using {int(\p+2)}, evaluate=\q as \v using {int(\q+1)}] in
{1/1/1/2, 1/1/2/2, 2/1/1/2, 2/1/2/2, 3/1/1/2, 3/1/2/2,
1/2/1/3, 1/2/2/3, 2/2/1/3, 2/2/2/3}{
\draw (\i-\j.center) node{$\bullet$} -- (\u-\v.center) node{$\bullet$};
};
\end{tikzpicture}
\end{NiceTabular}
\end{document}
结果是: