单个单元格格式

单个单元格格式

我的文件是

U(V)    I(A)    I/U
0.00    0.000   0 
0.31    0.020   0.065 
1.15    0.075   0.065 
1.82    0.120   0.0659
2.73    0.178   0.0652
3.42    0.224   0.0655
5.08    0.333   0.0656
6.24    0.408   0.0654
7.46    0.488   0.0654

我想使用 pgfplotstable 来显示这些数据。问题是,无论我怎么尝试,pgfplotstable 都会对数字进行四舍五入、添加零、使用科学计数法等...

在此处输入图片描述 我尝试添加string type, column type = {r}列,但现在无法以小数点为中心。

在此处输入图片描述

我希望 pgfplotstable 能够按我写的方式显示数字。我不想要多余的零、四舍五入的数字、固定的数字等等……

MWW:参见 Torbjørn T 的回答。

答案1

使用dec sep align,precision=4,并为前两列添加特定样式可能是您想要的。

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotstableread{
U(V)    I(A)    I/U
0.00    0.000   0 
0.31    0.020   0.065 
1.15    0.075   0.065 
1.82    0.120   0.0659
2.73    0.178   0.0652
3.42    0.224   0.0655
5.08    0.333   0.0656
6.24    0.408   0.0654
7.46    0.488   0.0654
}\data
\begin{document}

\pgfplotstabletypeset[
   dec sep align,
   precision=4,
   columns/U(V)/.style={fixed zerofill,precision=2},
   columns/I(A)/.style={fixed zerofill,precision=3},
   fixed,
   every head row/.style={
      before row=\toprule,
      after row=\midrule},
   every last row/.style={
      after row=\bottomrule}
   ]{\data}

\end{document}

单个单元格格式

您还可以为特定单元格添加样式,因此如果最后一列中有一个以零结尾的值,并且您希望将其包括在内,但不希望在该列的其​​他值中添加零,则可以使用样式every row <row index> column <column index>。请注意,索引从零开始计数。

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotstableread{
U(V)    I(A)    I/U
0.00    0.000   0 
0.31    0.020   0.065 
1.15    0.075   0.0650
1.82    0.120   0.0659
2.73    0.178   0.0652
3.42    0.224   0.0655
5.08    0.333   0.0656
6.24    0.408   0.0654
7.46    0.488   0.0654
}\data
\begin{document}

\pgfplotstabletypeset[
   dec sep align,
   precision=4,
   columns/U(V)/.style={fixed zerofill,precision=2},
   columns/I(A)/.style={fixed zerofill,precision=3},
   every row 2 column 2/.style={fixed zerofill,precision=4},
   fixed,
   every head row/.style={
      before row=\toprule,
      after row=\midrule},
   every last row/.style={
      after row=\bottomrule}
   ]{\data}

\end{document}

... 另一方面

对于这种情况,您还可以抛弃所有数字格式的内容,然后简单地说string type,column type={l}

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotstableread{
U(V)    I(A)    I/U
0.00    0.000   0 
0.31    0.020   0.065 
1.15    0.075   0.0650
1.82    0.120   0.0659
2.73    0.178   0.0652
3.42    0.224   0.0655
5.08    0.333   0.0656
6.24    0.408   0.0654
7.46    0.488   0.0654
}\data
\begin{document}

\pgfplotstabletypeset[
   string type,column type={l},
   every head row/.style={
      before row=\toprule,
      after row=\midrule},
   every last row/.style={
      after row=\bottomrule}
   ]{\data}

\end{document}

相关内容