![列表中的连接元素](https://linux22.com/image/458973/%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%BF%9E%E6%8E%A5%E5%85%83%E7%B4%A0.png)
如何连接这些元素以便我可以获得链接列表,foreach 需要保留因为它在我的项目中是必需的,如果有人可以帮忙的话?
\documentclass{article}
\usepackage{pgffor}
\usepackage{tikz}
\usepackage{xfp}
\usepackage{mathtools}
\usetikzlibrary{calc, shapes.multipart,chains, arrows}
\tikzstyle{node} = [draw, rectangle split *->, text left]
\tikzstyle{strela} = [thick, ->, >=stealth]
\newcommand\x{10}
\newcommand\y{3}
\begin{document}
\begin{tikzpicture}[list/.style={rectangle split, rectangle split parts=2,
draw, rectangle split horizontal}, start chain]
\foreach \i in {\the\numexpr\y,...,\the\numexpr\x}{
\node[list,on chain] (i) {\i};
\draw[*->] let \p1 = (i.two), \p2 = (i.center) in (\x1,\y2) -- (i);
}
\end{tikzpicture}
\end{document}
答案1
我认为有一个更优雅的解决方案,但这在某种意义上是有效的。
\documentclass{article}
\usepackage{pgffor}
\usepackage{tikz}
\usepackage{xfp}
\usepackage{mathtools}
\usetikzlibrary{calc, shapes.multipart,chains,arrows,positioning}
\newcommand\x{10}
\newcommand\y{3}
\begin{document}
\begin{tikzpicture}[ar/.style={*->,shorten <=-.28cm},list/.style={rectangle split, rectangle split parts=2, draw, rectangle split horizontal,join=by ar}, start chain=going right]
\foreach \i in {\the\numexpr\y,...,\the\numexpr\x}{
\node[list,on chain] (i) {\i};
}
\end{tikzpicture}
\end{document}