我想从文件中读取一个表格,其中每个单元格包含两个由 $\pm$ 运算符分隔的数字。我希望单元格在 $\pm$ 运算符处对齐。我当前的代码可以成功读取表格,但 $\pm$ 未对齐。
\documentclass{standalone}
\usepackage{pgfplotstable, booktabs}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{mydata}
Types,First Col,Second Col,Third Col
TypeA,-0.1575 $\pm$ 0.0118,-0.2428 $\pm$ 0.0074,-0.1457 $\pm$ 0.0078
TypeB, 0.0074 $\pm$ 0.0308,-0.276 $\pm$ 0.0251,-0.0181 $\pm$ 0.00173
\end{filecontents}
\pgfplotstabletypeset[
col sep=comma,
column type=l,
string type,
every head row/.style={
after row={
\midrule
},
},
every last row/.style={after row=\bottomrule},
display columns/0/.style={column type = {l|}},
display columns/1/.style={column type = {c|}},
display columns/2/.style={column type = {c|}},
display columns/3/.style={column type = {c}},
]{mydata}
\end{document}
任何帮助,将不胜感激。
答案1
嗯,那真是痛苦!
\documentclass{standalone}
\usepackage{pgfplotstable, booktabs}
\usepackage{filecontents}
\usepackage{siunitx}
\sisetup{separate-uncertainty,
uncertainty-separator={\pm},
table-figures-uncertainty=1,
table-number-alignment=center,
table-figures-decimal=5,% reserve space for 5 decimal places
output-open-uncertainty={},% prevents surrounding uncertainty with (...)
output-close-uncertainty={}}
\begin{document}
\begin{filecontents}{mydata}
Types,First Col,Second Col,Third Col
TypeA,-0.1575 $\pm$ 0.0118,-0.2428 $\pm$ 0.0074,-0.1457 $\pm$ 0.0078
TypeB, 0.0074 $\pm$ 0.0308,-0.276 $\pm$ 0.0251,-0.0181 $\pm$ 0.00173
\end{filecontents}
\pgfplotstabletypeset[
col sep=comma,
ignore chars={\$},% siunitx does not like $\pm$, but \pm is fine
string type,
%multicolumn names={l|},% do not apply S format to header
display columns/0/.style={column type = {l|}},
display columns/1/.style={column type = {S|},column name={\multicolumn{1}{l|}{First Col}}},
display columns/2/.style={column type = {S|},column name={\multicolumn{1}{l|}{Second Col}}},
display columns/3/.style={column type = {S},column name={\multicolumn{1}{l}{Third Col}}},
every head row/.style={
before row={\toprule},
after row={\midrule},
},
every last row/.style={after row=\bottomrule},
]{mydata}
\end{document}