Formatear celda tabular desde archivo csv automáticamente

Formatear celda tabular desde archivo csv automáticamente

Intenté adaptar ejemplos de5.4 Tablas con formato numéricodel csvsimplepaquete, pero sin éxito.

Cada línea de mi csvarchivo tiene 20 campos,todos ellostiene formato como x.xxxxxx. Aquí está la primera línea:

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

Me gustaría crear una tabla para imprimir los datos perotruncado, quiero decir, imprime solo 3 decimales como x.xxx.

Sé que \csvloop{}tiene la clave tabular={}para especificar el formato (como tabular={lSS[table-format=2.2e1]}en el ejemplo citado anteriormente).

  1. Dado que mi tabla debe tener 20 columnas, ¿es posibleformatear todo automáticamente?

  2. ¿Cuál debería ser el formato? S[table-format=1.3]?

MWE

El siguiente código produce el error.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}

Respuesta1

\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}

ingrese la descripción de la imagen aquí

información relacionada