pgfplotstable: Cómo manejar correctamente con pgfplotsinvokeforeach en pgfplotstablecreatecol

pgfplotstable: Cómo manejar correctamente con pgfplotsinvokeforeach en pgfplotstablecreatecol

Solo obtengo el último valor (es decir, '0') expandido en el siguiente pgfplotsinvokeforeach-loop.

¿Qué tengo que hacer?

Por cierto: me gustaría conservarlo create col/set list. Espero que sea posible.

ingrese la descripción de la imagen aquí

\documentclass[a4paper, landscape]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}

\begin{document}
\pgfplotstablenew[
create on use/Names/.style={create col/set list={
$k$,$k^2$,$k^3$}},
columns={Names}
]{7}\modulotable

\pgfplotsinvokeforeach{3,2,1,0}{%
% Calculations ================
\pgfmathsetmacro{\k}{#1}
\pgfmathsetmacro{\ksquare}{\k*\k}
\pgfmathsetmacro{\kcube}{\k*\k*\k}
% Column ===================
\pgfplotstablecreatecol[
create col/set list={\k,\ksquare,\kcube}
]{\k}\modulotable
}%
\pgfplotstabletypeset[string type]\modulotable

\end{document}

Respuesta1

\documentclass[a4paper, landscape]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}

\begin{document}
\pgfplotstablenew[
create on use/Names/.style={create col/set list={
$k$,$k^2$,$k^3$}},
columns={Names}
]{7}\modulotable

\pgfplotsinvokeforeach{3,2,1,0}{%
% Calculations ================
\pgfmathsetmacro{\k}{#1}
\pgfmathsetmacro{\ksquare}{\k*\k}
\pgfmathsetmacro{\kcube}{\k*\k*\k}
% Column ===================
\edef\next{%
\noexpand\pgfplotstablecreatecol[
  create col/set list={\k,\ksquare,\kcube}
  ]{\k}\noexpand\modulotable}\next
}%
\pgfplotstabletypeset[string type]\modulotable

\end{document}

ingrese la descripción de la imagen aquí

información relacionada