答案1
这是使用 的一种可能性\matrix
。代码中有一些注释,如果不清楚的话可以询问。
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
% hack for style of empty cells from https://tex.stackexchange.com/a/386805/
\tikzset{empty node/.style={coordinate}}
\makeatletter
\def\tikz@lib@matrix@empty@cell{\iftikz@lib@matrix@empty\node[name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn,empty node]{};\fi}
\makeatother
\begin{document}
\begin{tikzpicture}
\matrix [
% with the following option each cell becomes a node, set in math mode
% the nodes are named automatically as <matrix name>-<row number>-<column number>
matrix of math nodes,
nodes in empty cells, % add cells also to empty nodes
nodes={minimum width=1cm, minimum height=1cm, font=\strut} % set style of nodes
] (m) % give the matrix the name m
{
& \mu = 0 & 1 & 2 & 3 & \dots \\
\nu = 0 & & & & & \\
1 & & & & & \\
2 & & & & & \\
3 & & & & & \\
\vdots & & & & & \\
};
% for explanation of |- syntax: https://tex.stackexchange.com/a/401429/
% used to ensure horizontal/vertical lines
\draw (m-1-2.north west) -- (m-1-2.north west |- m-6-1.south east);
\draw (m-2-1.north west) -- (m-2-1.north west -| m-1-6.south east);
% due to the automatic node naming mentioned above, m-1-2 is the
% node in the first row, second column of the matrix
% a plot is an easy way of drawing a line with dots
\draw plot[mark=*] coordinates {(m-2-2)(m-2-3)(m-2-4)(m-3-4)(m-3-5)};
% for explanation of |- syntax: https://tex.stackexchange.com/a/401429/
% using that you only need to specify every other corner on the path
\draw (m-3-2) |- (m-4-3) |- (m-6-6);
% draw shifted, dotted line
% transform canvas idea from https://tex.stackexchange.com/a/180669/
\draw [dotted, transform canvas={shift={(5pt,5pt)}}] (m-3-2) |- (m-4-3) |- (m-6-6);
\end{tikzpicture}
\end{document}
答案2
使用{NiceArray}
和nicematrix
Tikz 使用 创建的 Tikz 节点绘制折线nicematrix
。
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\[
\begin{NiceArray}{c|ccccc}
& \mu = 0 & 1 & 2 & 3 & \cdots \\
\hline
\nu = 0 \\
1 \\
2 \\
3 \\
\vdots
\CodeAfter
\tikz [radius=2pt,every circle/.style = fill]
\draw plot [mark = *] coordinates
{(2.5-|2.5)(2.5-|3.5)(2.5-|4.5)(3.5-|4.5)(3.5-|5.5)(4.5-|5.5)(4.5-|6.5)(5.5-|6.5)} ;
\end{NiceArray}
\]
\[
\begin{NiceArray}{c|ccccccc}
& \mu = 0 & 1 & 2 & 3 & \cdot & \cdot & \cdot \\
\hline
\nu = 0 \\
1 \\
2 \\
\cdot \\
\cdot \\
\cdot \\
\CodeAfter
\begin{tikzpicture}
\draw (2.5-|2.5) -- (2.5-|4.5) |- (3.5-|5.5) |- (4.5-|6.5) |- (5.5-|7.5) ;
\draw (2.5-|2.5) -- (5.5-|2.5) -| (6.5-|3.5) -| (7.5-|4.5) ;
\draw [dotted]
([xshift=1mm]2.5-|2.5) |- (3.5-|3.5) |- (4.5-|4.5) |- (5.5-|5.5) |- (6.5-|6.5) ;
\end{tikzpicture}
\end{NiceArray}
\]
\end{document}