我正试图用pgfplots在乳胶中生成一些情节;由于我有几个不同的情节要制作,所以我尝试使用for循环。不幸的是,没有成功。实际上,代码被执行了三次,但是for循环的变量的值它总是等于定义循环的列表的第一个值。
例如,下面的最小代码
\documentclass[a4paper, 11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{groupplots}
\begin{document}
\makeatletter
\begin{tikzpicture}
\begin{groupplot}[group style={group size= 2 by 3}]
\@for\refin:={1,2,3}\do{%
\nextgroupplot[ylabel={$h = \frac{1}{\refin}$}]
\addplot {exp(x)};
\nextgroupplot
\addplot{2 * x};
}
\end{groupplot}
\end{tikzpicture}
\makeatother
\end{document}
生成一个有6个情节的图形(如预期的那样),但标签总是1/1,而不是1/2或1/3。为什么?
发布于 2021-11-30 14:38:44
您可以使用与https://tex.stackexchange.com/a/539754/36296相同的技巧:
\documentclass[a4paper, 11pt]{article}
\usepackage{pgffor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size= 2 by 3}]
\pgfplotsforeachungrouped \x in {1,2,3}{
\edef\tmp{
\noexpand\nextgroupplot[ylabel={$h = \frac{1}{\x}$}]
\noexpand\addplot {exp(x)};
}
\tmp
\nextgroupplot
\addplot{2 * x};
}
\end{groupplot}
\end{tikzpicture}
\end{document}
https://stackoverflow.com/questions/70170931
复制相似问题