我嘗試改編範例5.4 具有數字格式的表格來自csvsimple
包,但沒有成功。
我的文件中的每一行csv
都有 20 個字段,他們全部格式類似於x.xxxxxx
.這是第一行:
0.500000,0.614231,0.567667,0.580000,0.787222,0.510333,0.797333,0.732000,0.851228,0.804333,0.764000,0.730667,0.879667,0.778667,0.858333,0.726333,0.884000,0.772667,0.959545,0.919667
我想創建一個表格來列印資料但是被截斷的,我的意思是,只列印 3 個小數位,例如x.xxx
.
我知道有指定格式的\csvloop{}
關鍵(就像上面引用的範例一樣)。tabular={}
tabular={lSS[table-format=2.2e1]}
由於我的表格應該有 20 列,是否可以自動全部格式化?
格式應該是什麼?
S[table-format=1.3]
?
微量元素
下面的程式碼會產生錯誤You can't use a prefix with \hskip.}
\documentclass{report}
\usepackage{filecontents}
\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{array}
\begin{document}
\begin{filecontents*}{tab2.csv}
0.500000,0.614231,0.567667,0.580000,0.787222,0.510333,0.797333,0.732000,0.851228,0.804333,0.764000,0.730667,0.879667,0.778667,0.858333,0.726333,0.884000,0.772667,0.959545,0.919667
0.000000,0.500000,0.867308,0.891667,0.763889,0.694872,0.785256,0.729647,0.844298,0.797917,0.709455,0.675641,0.876282,0.741667,0.851442,0.710256,0.880128,0.694872,0.949519,0.912500
\end{filecontents*}
%
\csvloop{
file=tab2.csv,
tabular=*{20}{S[table-format=1.3,round-mode=places,round-precision=3]},
}
\end{document}
答案1
\documentclass{article}
\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{filecontents}
\begin{filecontents*}{BC14.csv}
0.500000,0.614231,0.567667,0.580000,0.787222,0.510333,0.797333,0.732000,0.851228,0.804333,0.764000,0.730667,0.879667,0.778667,0.858333,0.726333,0.884000,0.772667,0.959545,0.919667
0.000000,0.500000,0.867308,0.891667,0.763889,0.694872,0.785256,0.729647,0.844298,0.797917,0.709455,0.675641,0.876282,0.741667,0.851442,0.710256,0.880128,0.694872,0.949519,0.912500
\end{filecontents*}
\setlength{\tabcolsep}{1pt}
\begin{document}
{
\footnotesize
\csvreader[%
no head,
before reading=\sisetup{table-format=1.3,round-mode=places,round-precision=3},
tabular={c@{} *{20}{S}},
]{BC14.csv}{}{%
& \csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix & \csvcolx & \csvcolxi & \csvcolxii & \csvcolxiii & \csvcolxiv & \csvcolxv & \csvcolxvi & \csvcolxvii & \csvcolxviii & \csvcolxix & \csvcolxx
}
}
\end{document}