![为什么 TikZ/pgf 的 \foreach[remember] 不适用于显式列表?](https://linux22.com/image/321774/%E4%B8%BA%E4%BB%80%E4%B9%88%20TikZ%2Fpgf%20%E7%9A%84%20%5Cforeach%5Bremember%5D%20%E4%B8%8D%E9%80%82%E7%94%A8%E4%BA%8E%E6%98%BE%E5%BC%8F%E5%88%97%E8%A1%A8%EF%BC%9F.png)
简短版本:当使用时\foreach \x in [remember=\x as \lastx]
,迭代in {1,...,3}
有效,但迭代in {1,2,3}
无效。
我已阅读了手册段落,/pgf/foreach/remember
但没有看到任何内容表明为什么会出现这种情况。
这在迭代多个数值变量时尤其麻烦,因为x0/y0,...,xn/yn
不管怎样,这似乎都不起作用。当然,当你的列表只是没有遵循算术序列。
梅威瑟:
\documentclass{standalone} % same outcome with article
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) node[above] {
\foreach \x [
remember=\x as \lastx (initially 0)
] in {1,2,3}
{\x, \lastx;\quad}
};
\draw (0, -1) node[above] {
\foreach \x [
remember=\x as \lastx (initially 0)
] in {1,...,3}
{\x, \lastx;\quad}
};
\draw (0, -2) node[above] {
\foreach \x / \y [
remember=\x as \lastx (initially 0),
remember=\y as \lasty (initially 0),
] in {1/11,2/22,3/13}
{$(\x,\y), (\lastx,\lasty)$;\quad}
};
\end{tikzpicture}
\end{document}
如果这不是一个如此普遍的用例,我会倾向于认为这是一个错误……