pgfplotstable: pgfplotstablecreatecol에서 pgfplotsinvokeforeach를 사용하여 올바르게 처리하는 방법

pgfplotstable: pgfplotstablecreatecol에서 pgfplotsinvokeforeach를 사용하여 올바르게 처리하는 방법

다음 pgfplotsinvokeforeach-loop에서 확장된 마지막 값(즉 '0')만 얻습니다.

내가 무엇을 해야 합니까?

참고: 나는 create col/set list. 가능하길 바랍니다.

여기에 이미지 설명을 입력하세요

\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}

답변1

\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}

여기에 이미지 설명을 입력하세요

관련 정보