2

I have an issue in correctly changing the column width of a table. I want the columns to be formatted using the siunitx package. In my data, I have a mix of values that should be printed as is (e.g. 0.0425) and some that should be printed with the float shift (3.585 * 10 ^ -5).

When I change the column width using the table-column-width property of the S column, the values do not align any longer. It seems like the normal floating point numbers do behave as expected and the numbers with a power of 10 are in the place where they would be without column resizing.

To setup the data you can use

\documentclass{minimal}

\begin{document}

\begin{filecontents*}{data.csv}
Parameter,200,600,No-Treatment
N-Observations,209.0,209.0,195.0
Mean,2.500170353865091e-05,2.1559213174203927e-05,0.00015240802982599504
Variance,5.5824149143594136e-08,-1.1650000181975986e-08,1.7979465607149884e-07
Skewness,-0.4393776076843506,-0.06577317175679437,-0.13945687546114036
\end{filecontents*}

\end{document}

A MWE to see the issue is here:

\documentclass{paper}

\usepackage{array}
\usepackage{booktabs} % version 1.61803398
\usepackage{siunitx} % version 2.8b

\sisetup{
  round-mode          = places, % Rounds numbers
  round-precision     = 4, % to 4
}

\usepackage{pgfplotstable} % version 1.17
\pgfplotsset{compat=newest}

\begin{document}


\begin{table}[ht]
    \centering
    \caption{Statistical parameters example}
    \pgfplotstabletypeset[
      multicolumn names, % allows to have multicolumn names
      col sep=comma, % the seperator in our .csv file
      display columns/0/.style={
        column name=Parameter, % name of first column
        column type={p{0.25\textwidth}|},string type},  % use siunitx for formatting
      display columns/1/.style={
        column type={S[table-column-width=3cm]},string type},  % use siunitx for formatting
      display columns/2/.style={
        column type={S[table-column-width=3cm]},string type},  % use siunitx for formatting
      display columns/3/.style={
        column type={S[table-column-width=3cm]},string type},  % use siunitx for formatting
      every head row/.style={
        before row={\toprule}, % have a rule at top
        after row={\midrule},
        every last row/.style={after row=\bottomrule}
        }
    ]{data/stat-windows-mean.csv} % filename/path to file
\end{table}

\end{document}
2
  • 1
    I'm guessing you are using siunitx version 2: correct?
    – Joseph Wright
    Commented Jun 10, 2021 at 20:55
  • Yes, I am using siunitx version 2.8b
    – Philipp P
    Commented Jun 11, 2021 at 7:17

1 Answer 1

1

The v2 code does have an issue here, but even in v3 (which does not have a bug in the fixed-width approach), I'd still use table-format to define some reserved space:

\begin{filecontents*}{data.csv}
Parameter,200,600,No-Treatment
N-Observations,209.0,209.0,195.0
Mean,2.500170353865091e-05,2.1559213174203927e-05,0.00015240802982599504
Variance,5.5824149143594136e-08,-1.1650000181975986e-08,1.7979465607149884e-07
Skewness,-0.4393776076843506,-0.06577317175679437,-0.13945687546114036
\end{filecontents*}

\documentclass{article}

\usepackage{array}
\usepackage{booktabs}
\usepackage{siunitx}%[=v2]

\sisetup{
  round-mode          = places, % Rounds numbers
  round-precision     = 4, % to 4
}

\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

\begin{document}


\begin{table}[ht]
  \sisetup{table-column-width=3cm,table-format = 3.4e+1}
    \centering
    \caption{Statistical parameters example}
    \pgfplotstabletypeset[
      multicolumn names, % allows to have multicolumn names
      col sep=comma, % the seperator in our .csv file
      display columns/0/.style={
        column name=Parameter, % name of first column
        column type={p{0.25\textwidth}|},string type},  % use siunitx for formatting
      display columns/1/.style={
        column type={S},string type},  % use siunitx for formatting
      display columns/2/.style={
        column type={S},string type},  % use siunitx for formatting
      display columns/3/.style={
        column type={S},string type},  % use siunitx for formatting
      every head row/.style={
        before row={\toprule}, % have a rule at top
        after row={\midrule},
        every last row/.style={after row=\bottomrule}
        }
    ]{data.csv} % filename/path to file
\end{table}

\end{document}

The v3 code makes a better effort here, but you will need to add table-fixed-width as I've split the idea of 'storing a column width' and 'using a fixed column width'.

2
  • Not part of the answer, but I would avoid a fixed-width column for numbers
    – Joseph Wright
    Commented Jun 11, 2021 at 9:04
  • By fixed-width you mean fixed width in general (also using \textwidth) or just fixing it to a value in cm?
    – Philipp P
    Commented Jun 11, 2021 at 9:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .