我用它pgfplotstabletypeset
来获取数据并将它们存储在表中。一切都运行良好。但是当我尝试$\Delta$
在表的列中使用符号 delta ( ) 时,它不起作用,我不知道为什么。
以下是一个例子:
\documentclass{standalone}
\usepackage{pgfplotstable,filecontents}
\pgfplotsset{compat=1.9}% supress warning
\begin{filecontents*}{test2.csv}
Time (s),Zeroed time (s),$\Delta$T
43.97,0,23
44.01,0.04,32
44.04,0.07,45
44.07,0.1,86
44.11,0.14,92
44.14,0.17,100
44.17,0.2,101
44.21,0.24,102
44.24,0.27,103
44.27,0.3,115
\end{filecontents*}
\begin{document}
\pgfplotstabletypeset[col sep=comma,
columns={Zeroed time (s),$\Delta$T},
]{test2.csv}
\end{document}
此外,我还有以下我不理解的警告(这与我遇到的符号问题无关):
LaTeX Warning : Writing file './test2.csv' [...]
我知道 LaTeX 正在编写 csv 文件,但为什么这如此重要而被视为警告?..
答案1
问题在于,它pgfplotstable
以某种方式特殊处理头行,不允许某些输入和/或格式。
如果你将示例更改为
\documentclass{standalone}
\usepackage{pgfplotstable,filecontents}
\pgfplotsset{compat=1.9}% supress warning
\begin{filecontents*}{test2.csv}
Time (s),Zeroed time (s),$\Delta$ T
43.97,0,23
44.01,0.04,32
44.04,0.07,45
44.07,0.1,86
44.11,0.14,92
44.14,0.17,100
44.17,0.2,101
44.21,0.24,102
44.24,0.27,103
44.27,0.3,115
\end{filecontents*}
\begin{document}
\pgfplotstabletypeset[%
col sep=comma,%
header=false,%
string type,%
every head row/.style={output empty row},%
columns={1,2},%
]{test2.csv}
\end{document}
它会起作用的。
那么我做了什么?
- 我使用该选项阻止包将每个单元格的内容解释为数字
string type
。这样,单元格中也可以使用普通文本 - 我使用以下方法抑制了虚拟头行(显示列索引)的创建
every head row/.style={output empty row}
- 由于不再有头行,列不再采用输入数据第一行中指定的名称。因此,您必须通过索引引用列(如您在选项中看到的那样
columns={1,2}
)。
如果您仍希望通过以下方式排版所有数字,\pgfmathprintnumber
则必须对单元格内容分配进行一些调整:
\pgfplotstableset{
/pgfplots/table/assign cell content/.code={%
\normalexpandarg%
\IfDecimal{#1}{%
% format as number
\pgfmathprintnumberto{#1}\result
\pgfkeyslet{/pgfplots/table/@cell content}\result
}{%
% use as String -> has to span two columns if col sep align is activated
\ifnum\pgfplotstablepartno=0%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\noexpand{#1}}%
\fi%
}%
},%
}
使用此选项时,您可以省略该string type
选项,让算法决定是否将单元格格式化为数字或字符串。因此,您的示例将如下所示(请注意,以上代码取决于包xstring
):
\documentclass{standalone}
\usepackage{pgfplotstable,filecontents,xstring}
\pgfplotsset{compat=1.9}% supress warning
\begin{filecontents*}{test2.csv}
Time (s),Zeroed time (s),$\Delta$ T
43.97,0,23
44.01,0.04,32
44.04,0.07,45
44.07,0.1,86
44.11,0.14,92
44.14,0.17,100
44.17,0.2,101
44.21,0.24,102
44.24,0.27,103
44.27,0.3,115
\end{filecontents*}
\pgfplotstableset{
/pgfplots/table/assign cell content/.code={%
\normalexpandarg%
\IfDecimal{#1}{%
% format as number
\pgfmathprintnumberto{#1}\result
\pgfkeyslet{/pgfplots/table/@cell content}\result
}{%
% use as String -> has to span two columns if col sep align is activated
\ifnum\pgfplotstablepartno=0%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\noexpand{#1}}%
\fi%
}%
},%
}
\begin{document}
\pgfplotstabletypeset[%
col sep=comma,%
header=false,%
every head row/.style={output empty row},%
columns={1,2},%
]{test2.csv}
\end{document}
如果您想要添加一些上划线和下划线,则必须使用every first row
和every last row
键(我正在使用该booktabs
包来创建水平线):
\documentclass{standalone}
\usepackage{pgfplotstable,filecontents,xstring, booktabs}
\pgfplotsset{compat=1.9}% supress warning
\begin{filecontents*}{test2.csv}
Time (s),Zeroed time (s),$\Delta$ T
43.97,0,23
44.01,0.04,32
44.04,0.07,45
44.07,0.1,86
44.11,0.14,92
44.14,0.17,100
44.17,0.2,101
44.21,0.24,102
44.24,0.27,103
44.27,0.3,115
\end{filecontents*}
\pgfplotstableset{
/pgfplots/table/assign cell content/.code={%
\normalexpandarg%
\IfDecimal{#1}{%
% format as number
\pgfmathprintnumberto{#1}\result
\pgfkeyslet{/pgfplots/table/@cell content}\result
}{%
% use as String -> has to span two columns if col sep align is activated
\ifnum\pgfplotstablepartno=0%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\noexpand{#1}}%
\fi%
}%
},%
}
\begin{document}
\pgfplotstabletypeset[%
col sep=comma,%
header=false,%
every head row/.style={output empty row},%
columns={1,2},%
every first row/.append style={before row=\toprule,after row=\midrule},%
every last row/.append style={after row=\bottomrule},%
]{test2.csv}
\end{document}
这将导致
然后,您可以继续照常更改数字打印选项(例如使用选项fixed
)。dec sep align
在大多数情况下,即使应该也可以工作,尽管上面提供的“单元格内容分配”算法可能存在一些问题...