以下是我正在使用的代码:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{measurements.dat}
sample num-bugs num-part other-measure another
5 80 190 200 210
15 520 410 430 350
25 650 640 630 900
35 1100 1200 1150 1020
\end{filecontents}
\usepackage{pgfplots, pgfplotstable, booktabs, colortbl}
\pgfplotsset{compat=1.7}
\pgfplotstableset{
every head row/.style=
{before row={\toprule},
after row={\midrule}},
every last row/.style=
{after row={\bottomrule}},
every even row/.style=
{before row={\rowcolor[gray]{0.9}}},
columns/.style=
{dec sep align,
%column type=c
}
}
\begin{document}
\pgfplotstabletypeset[
columns={sample, another, num-part},
columns/sample/.style={
column name={Sample},
}
]{measurements.dat}
\end{document}
这会导致数据按预期在小数点处对齐。但是,数据也在 处对齐l
。我需要它在 处对齐c
,因此我添加了选项
columns/.style={column type=c}
(如上文注释所示)。
这会产生错误:
ERROR: Extra alignment tab has been changed to \cr.
--- TeX said ---
<template> \endtemplate
l.31 ]{measurements.dat}
--- HELP ---
There are too many separate items (column entries) in a single row of
an array or tabular environment. In other words, there were too many &
's before the end of the row. You probably forgot the \\ at the end of
the preceding row.
我怎样才能实现居中和对齐列?
例子
Header1 Header2 LongerHeader3 HeaderWithoutARealName4
1.0 2.0 3.0 4.0
2.0 13.0 4 1234567890.23
当前左对齐结果
答案1
这对你有用吗?它用于格式化列。和siunitx
之间似乎存在一些问题,因此必须单独格式化每列,并且必须在括号中提供列名。如果不行,siunitx 会抱怨每个siunitx
pgfplotstable
埃在列名中。也许这里的一些巫师知道如何解决这个问题。
平均能量损失
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{measurements.dat}
sample num-bugs num-part other-measure another
5 80 190 200 210.02
15 520 410.00 430 350
25 650 640 630.2 900
35 1100 1200 1150 1020
\end{filecontents}
\usepackage{pgfplots, pgfplotstable, booktabs, colortbl, siunitx, array}
\pgfplotsset{compat=1.8}
\begin{document}
\pgfplotstabletypeset[
assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{{#1}}},
columns={sample, another, num-part},
every head row/.style=
{before row={\toprule},
after row={\midrule}},
every last row/.style=
{after row={\bottomrule}},
every even row/.style=
{before row={\rowcolor[gray]{0.9}}},
columns/sample/.style={
assign column name={Sample},
column type={S[]}, string type,
},
columns/another/.style={%
assign column name={Another},
column type={S[]}, string type,
},
columns/num-part/.style={%
assign column name={Num-Part},
column type={S[]}, string type,
},
% Does produce the desired effect
% columns/.style={column type={S[]}, string type,},
]{measurements.dat}
\end{document}