2

I'm trying to define a csvstyle that I can use for multiple tables using csvreader, however I'm running into errors trying to separately format 'S' columns. Each table has the same column names and data types; they are simply results from differing experimental scenarios.

For the following data:

Dataset1.csv

Name,ValueA,ValueB,ValueC
John,623.95, 8.954847, 0.000772
Anna,602.40,8.93469, 0.000772
Jacob,1987.17,8.796296, 0.000926

This is the furthest I can get:

\documentclass{article}
\usepackage{csvsimple}
\usepackage{filecontents}
\usepackage{siunitx}

\begin{filecontents*}{Dataset1.csv}
Name,ValueA,ValueB,ValueC
John,623.95, 8.954847, 0.000772
Anna,602.40,8.93469, 0.000772
Jacob,1987.17,8.796296, 0.000926
\end{filecontents*}

\begin{document}
\csvstyle{MyStyle}{
    head to column names,
    before reading=\centering\sisetup{table-number-alignment=center,table-format=4.4,table-auto-round},
    tabular=|c|S|S|S|,
    table head =\hline {Name} & {ValueA} & {ValueB} & {ValueC} \\\hline,
    table foot=\hline
}

\csvreader[MyStyle]{Dataset1.csv}{}{\Name & \ValueA & \ValueB & \ValueC}
\end{document}
%\csvreader[MyStyle]{Dataset2.csv}{}{\Name & \ValueA & \ValueB & \ValueC}
\end{document}

Current Coding Results

Any attempt to change an S into an S[table-format=4.2] (and remove it from before reading) so that I can column-by-column adjust the number of decimal places yields a

Paragraph ended before \\NC@rewrite@S was complete. ...sv}{}{\Name & \ValueA & \ValueB & \ValueC}

error. Any assistance would be greatly appreciated.

3

You can instead define the desired format as a new column type:

\newcolumntype{H}{S[table-format=4.2]}

Then you can use H instead of S, when desired and remove the format command from your before reading macro.

I have created an example of this on Overleaf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.