
Ich bekomme nur den letzten Wert (also „0“) erweitert in der folgenden pgfplotsinvokeforeach-Schleife.
Was muss ich tun?
Übrigens: Ich würde es gerne behalten create col/set list
. Ich hoffe, es ist möglich.
\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}
Antwort1
\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}