我用pgfplotstable
它来生成要在线提交给期刊的表格。我希望我的论文能够独立于此,pgfplotsable
因为文档的编译是使用过时的 LaTeX 发行版和笨拙的软件包处理在线完成的。
我已经问过一个这样的问题(见这个问题),但现在我面临的情况更为复杂。通过这个,我了解了将表写入文件outfile=
的命令选项。\pgfplotstabletypeset
我正在使用的一些功能pgfplotstable
将表格中的数字替换为符号(灵感来自这个问题)这里有一个与我的实际代码类似的示例:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableset{symbol column/.style={column type=c,
postproc cell content/.style={
/pgfplots/table/@cell content={}{%
\pgfmathparse{int(less(##1, 0.01))}
\ifnum\pgfmathresult=1
*
\else
\pgfmathparse{int(less(##1, .1))}
\ifnum\pgfmathresult=1
**
\else
\pgfmathparse{int(less(##1,1))}
\ifnum\pgfmathresult=1
***
\else
{ }
\fi
\fi
\fi
},
},
}}
\pgfplotstabletypeset[outfile=output_table.tex,
columns/A/.style={symbol column},
columns/B/.style={symbol column},
]
{%
A B
.001 5
.1 .5
.2 .005
1.7 22
}
\end{document}
输出文件如下所示:
\begin {tabular}{cc}%
A&B\\%
{}{\pgfmathparse {int(less(.001, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.001, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.001,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(5, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(5, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(5,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
{}{\pgfmathparse {int(less(.1, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.1, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.1,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(.5, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.5, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.5,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
{}{\pgfmathparse {int(less(.2, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.2, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.2,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(.005, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.005, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.005,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
{}{\pgfmathparse {int(less(1.7, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(1.7, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(1.7,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(22, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(22, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(22,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
\end {tabular}%
这取决于pgf
和\pgfmathparse
相关命令。
有没有办法解决这个问题,而无需手动编辑表格或使用外部程序
答案1
一般来说这可能很难,但在这里你只使用 pgfmath 进行不等式测试,这是一个你可以避免的困难:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableset{symbol column/.style={column type=c,
postproc cell content/.style={
/pgfplots/table/@cell content={}{%
\ifdim##1pt <0.01pt
*
\else
\ifdim##1pt <0.1pt
**
\else
\ifdim##1pt <1pt
***
\else
{ }
\fi
\fi
\fi
},
},
}}
\pgfplotstabletypeset[outfile=output_table.tex,
columns/A/.style={symbol column},
columns/B/.style={symbol column},
]
{%
A B
.001 5
.1 .5
.2 .005
1.7 22
}
\end{document}
生产
\begin {tabular}{cc}%
A&B\\%
{}{\ifdim .001pt <0.01pt * \else \ifdim .001pt <0.1pt ** \else \ifdim .001pt <1pt *** \else
{ } \fi \fi \fi }&{}{\ifdim 5pt <0.01pt * \else \ifdim 5pt <0.1pt ** \else \ifdim 5pt <1pt
*** \else { } \fi \fi \fi }\\%
{}{\ifdim .1pt <0.01pt * \else \ifdim .1pt <0.1pt ** \else \ifdim .1pt <1pt *** \else { } \
fi \fi \fi }&{}{\ifdim .5pt <0.01pt * \else \ifdim .5pt <0.1pt ** \else \ifdim .5pt <1pt **
* \else { } \fi \fi \fi }\\%
{}{\ifdim .2pt <0.01pt * \else \ifdim .2pt <0.1pt ** \else \ifdim .2pt <1pt *** \else { } \
fi \fi \fi }&{}{\ifdim .005pt <0.01pt * \else \ifdim .005pt <0.1pt ** \else \ifdim .005pt <
1pt *** \else { } \fi \fi \fi }\\%
{}{\ifdim 1.7pt <0.01pt * \else \ifdim 1.7pt <0.1pt ** \else \ifdim 1.7pt <1pt *** \else {
} \fi \fi \fi }&{}{\ifdim 22pt <0.01pt * \else \ifdim 22pt <0.1pt ** \else \ifdim 22pt <1pt
*** \else { } \fi \fi \fi }\\%
\end {tabular}%
答案2
根据 Christian 的评论,我编写了以下代码:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\newcommand{\filtercode}{%
\pgfmathparse{int(less(\cellvalue, 0.01))}%
\ifnum\pgfmathresult=1 %
\edef\cellvalue{x}%
\else
\pgfmathparse{int(less(\cellvalue, .1))}%
\ifnum\pgfmathresult=1 %
\edef\cellvalue{xx}%
\else
\pgfmathparse{int(less(\cellvalue,1))}%
\ifnum\pgfmathresult=1 %
\edef\cellvalue{xxx}%
\else
\edef\cellvalue{Z}%
\fi
\fi
\fi
\toks0=\expandafter{\cellvalue}%
\edef\value{{}\the\toks0}%
%\show\value
\pgfkeyslet{/pgfplots/table/create col/next content}\value
}
\pgfplotstableset{%
create on use/AA/.style={create col/assign/.code={%
\getthisrow{A}\cellvalue\filtercode}},%
create on use/BB/.style={create col/assign/.code={%
\getthisrow{B}\cellvalue\filtercode}},%
}
\pgfplotstabletypeset[outfile=output_table.tex,
columns/AA/.style={string type, column type=c},
columns/BB/.style={string type, column type=c},
% debug,
columns={AA, BB}
]
{%
A B
.001 5
.0001 .5
.2 .005
1.7 22
}
\end{document}
它产生这个输出
\begin {tabular}{cc}%
AA&BB\\%
{}x&{}Z\\%
{}x&{}xxx\\%
{}xxx&{}x\\%
{}Z&{}Z\\%
\end {tabular}%
这正是我所寻找的。