Tentei adaptar exemplos de5.4 Tabelas com Formatação Numéricado csvsimple
pacote, mas sem sucesso.
Cada linha do meu csv
arquivo possui 20 campos,todos elestem formato como x.xxxxxx
. Aqui está a primeira linha:
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
Eu gostaria de criar uma tabela para imprimir os dados, mastruncado, quero dizer, imprima apenas 3 casas decimais como x.xxx
.
Eu sei que \csvloop{}
tem a chave tabular={}
para especificar o formato (como tabular={lSS[table-format=2.2e1]}
no exemplo citado acima).
Como meu tabular deveria ter 20 colunas, é possívelformatar tudo automaticamente?
Qual deve ser o formato?
S[table-format=1.3]
?
MWE
O código abaixo produz o erroYou 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}
Responder1
\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}