
我有这个:
\begin{tabular}{ c c c c c c c c c c }
0 & 1 & 3 & 6 & 10 & 15 & 21 & 28 & 36& \dots \\
2 & 4 & 7 & 11 & 16 & 22 & 29 & 37 & \dots& \dots \\
5 & 8 & 12 & 17 & 23 & 30 & 38 & \dots & \dots& \dots \\
9 & 13 & 18 & 24 & 31 & 39 & \dots & \dots & \dots& \dots \\
14 & 19 & 25 & 32 & 40& \dots & \dots & \dots & \dots& \dots \\
20 & 26 & 33 & 41& \dots & \dots & \dots & \dots & \dots& \dots \\
27 & 34 &42 & \dots & \dots & \dots & \dots & \dots & \dots& \dots \\
35 & 43 & \dots & \dots & \dots & \dots & \dots & \dots & \dots& \dots \\
44& \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots& \dots \\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots& \dots \\
\end{tabular}
我试图在点之间画一些曲折的对角线路径,类似于这样:
我怎样才能在 LaTex 中实现类似的效果?(不必与图片完全一样,只要概念相同即可)
答案1
这是浮现在我硬盘里的东西,我并不是为这个问题画的。
\documentclass[]{standalone}
\usepackage{tikz}
\usepackage{xfrac}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[myarrow/.style={red,->,shorten >=0.25cm, shorten <=.25cm}]
\matrix (m) [draw,matrix of nodes,inner sep=.2cm,ampersand replacement=\&]
{
$\sfrac{1}{1}$ \& $\sfrac{1}{2}$ \& $\sfrac{1}{3}$ \& $\sfrac{1}{4}$ \& $...$\\
$\sfrac{2}{1}$ \& $\sfrac{2}{2}$ \& $\sfrac{2}{3}$ \& $\sfrac{2}{4}$ \& $...$\\
$\sfrac{3}{1}$ \& $\sfrac{3}{2}$ \& $\sfrac{3}{3}$ \& $\sfrac{3}{3}$ \& $...$\\
$\sfrac{4}{1}$ \& $\sfrac{4}{2}$ \& $\sfrac{4}{3}$ \& $\sfrac{4}{4}$ \& $...$\\
$...$\\
};
\draw[myarrow] (m-1-1.center)--(m-2-1.center);
\draw[myarrow] (m-2-1.center)--(m-1-2.center);
\draw[myarrow] (m-1-2.center)--(m-1-3.center);
\draw[myarrow] (m-1-3.center)--(m-2-2.center);
\draw[myarrow] (m-2-2.center)--(m-3-1.center);
\draw[myarrow] (m-3-1.center)--(m-4-1.center);
\draw[myarrow] (m-4-1.center)--(m-3-2.center);
\draw[myarrow] (m-3-2.center)--(m-2-3.center);
\draw[myarrow] (m-2-3.center)--(m-1-4.center);
\draw[myarrow] (m-1-4.center)--(m-2-4.center);
\draw[myarrow,-,dotted] (m-2-4.center)--(m-3-3.center);
\end{tikzpicture}
\end{document}
一旦获得矩阵命名方案,您就可以根据需要轻松更改箭头流。
答案2
使用{NiceMatrix}
和nicematrix
TikZ来绘制规则。
\documentclass{standalone}
\usepackage{nicematrix}
\usepackage{tikz}
\usepackage{xfrac}
\begin{document}
\renewcommand{\arraystretch}{1.4}
$\begin{NiceMatrix}
\sfrac{1}{1} & \sfrac{1}{2} & \sfrac{1}{3} & \sfrac{1}{4} & ...\\
\sfrac{2}{1} & \sfrac{2}{2} & \sfrac{2}{3} & \sfrac{2}{4} & ...\\
\sfrac{3}{1} & \sfrac{3}{2} & \sfrac{3}{3} & \sfrac{3}{3} & ...\\
\sfrac{4}{1} & \sfrac{4}{2} & \sfrac{4}{3} & \sfrac{4}{4} & ...\\
...\\
\CodeAfter
\begin{tikzpicture} [->,red]
\draw (1-1)--(2-1);
\draw (2-1)--(1-2);
\draw (1-2)--(1-3);
\draw (1-3)--(2-2);
\draw (2-2)--(3-1);
\draw (3-1)--(4-1);
\draw (4-1)--(3-2);
\draw (3-2)--(2-3);
\draw (2-3)--(1-4);
\draw (1-4)--(2-4);
\draw [dotted] (2-4)--(3-3);
\end{tikzpicture}
\end{NiceMatrix}$
\end{document}