我创建了一个表格,\pgfplotsforeachungrouped
并测试数字是偶数还是奇数。
\pgfmathsetmacro\eotest{mod(\n,2)==0 ? 1 : 0}
在循环中正常工作。循环中的
For \ifnum\eotest=1 \def\eoword{even} \else \def\eoword{odd} \fi
ADirect writeout: \n, \eotest, \eoword \\
也正常工作。
但如果我把这些都放进\pgfplotstable
,那就意味着
create on use/eoword/.style={create col/set={\eoword}}
'
eoword' 无法正确显示。
它只会返回列表中的最后一个条目。
我应该做些什么不同的事情?
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\begin{document}
\section{Table Row by Row with a Loop}
\pgfplotsforeachungrouped \n in {0,...,8}{%%
% works:
\pgfmathsetmacro\eotest{mod(\n,2)==0 ? 1 : 0}
%Problem here ========================
\ifnum\eotest=1 \def\eoword{even} \else \def\eoword{odd} \fi% eoword 1/3
%Direct writeout: {\n, \eotest, \eoword} works well \\
% ================================
\pgfplotstablenew[
create on use/No/.style={create col/expr={\n}},
create on use/eotest/.style={create col/expr={\eotest}},
create on use/eoword/.style={create col/set={\eoword}},% eoword 2/3
columns={No, eotest, eoword}
]{1}\temptable
\pgfplotstablevertcat{\table}{\temptable}%
}%%
\pgfplotstabletypeset[
columns/eoword/.style={string type},% eoword 3/3
]{\table}
\end{document}
答案1
您希望.estyle
在设置键时扩展该值。
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\begin{document}
\section{Table Row by Row with a Loop}
\pgfplotsforeachungrouped \n in {0,...,8}{%%
\pgfmathsetmacro\eotest{mod(\n,2)==0 ? 1 : 0}%
\ifnum\eotest=1 \def\eoword{even} \else \def\eoword{odd} \fi% eoword 1/3
\pgfplotstablenew[
create on use/No/.style={create col/expr={\n}},
create on use/eotest/.estyle={create col/expr={\eotest}},
create on use/eoword/.estyle={create col/set={\eoword}},% eoword 2/3
columns={No, eotest, eoword}
]{1}\temptable
\pgfplotstablevertcat{\table}{\temptable}%
}
\pgfplotstabletypeset[
columns/eoword/.style={string type},% eoword 3/3
]{\table}
\end{document}