答案1
如果你接受纯TikZ
解决方案:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning,matrix, arrows.meta}
\begin{document}
\begin{tikzpicture}
\matrix (A) [matrix of nodes, nodes={draw, minimum size=8mm},
column sep=-\pgflinewidth]{
3 & 4 & 2 & 1 & 4 & 1 & 2 & 3\\};
\foreach \i [evaluate=\i as \ni using {int(\i)},
evaluate=\i as \ntext using {int(\i-1)}] in {1,3,4,6}
\draw [{Stealth}-, red!70] (A-1-\ni.south west)--++(-90:5mm) node[below] {\ntext};
\end{tikzpicture}
\end{document}
答案2
使用{NiceTabular}
和nicematrix
TikZ 创建的 PGF/TikZ 节点绘制箭头nicematrix
。
\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{NiceTabular}{*{8}{c}}[hvlines]
3 & 4 & 2 & 1 & 4 & 1 & 2 & 3
\CodeAfter
\begin{tikzpicture} [{Stealth}-,red]
\draw (2-|1) -- ++(0,-4mm) node [below] {0} ;
\draw (2-|3) -- ++(0,-4mm) node [below] {2} ;
\draw (2-|4) -- ++(0,-4mm) node [below] {3} ;
\draw (2-|6) -- ++(0,-4mm) node [below] {5} ;
\end{tikzpicture}
\end{NiceTabular}
\end{document}
答案3
还有一个普通的 TikZ 解决方案:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[thick,scale=.6]
\draw (0,0) grid (8,1);
\path (.5,.5) node{$3$} ++(1,0) node{$4$}
++(1,0) node{$2$} ++(1,0) node{$1$} ++(1,0) node{$4$}
++(1,0) node{$1$} ++(1,0) node{$2$} ++(1,0) node{$3$};
\foreach \i in {0,2,3,5}
\draw[latex-,red] (\i,0)--+(-90:1) node[below,black]{$\i$};
\end{tikzpicture}
\end{document}
PS:您可以使用foreach
来path
缩短代码
\path (.5,.5) node{$3$} foreach \i in {4,2,1,4,1,2,3} {++(1,0) node{$\i$}};