나는 다음의 예를 적용하려고 노력했습니다.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]
?
MWE
아래 코드는 오류를 생성합니다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}