1

I'm reproducing an example from this tutorial. If the input from the csv file is numeric, it works well. However, if one of the columns of the csv contains alphabetic characters, it returns an error message.

I added string type, after seeing this question, to no avail.

I've been tinkering a while with it and considered reading the pgfplotstable manual from cover to cover and try to make a custom table from scratch. However, that defeats the purpose of taking advantage of an 'already cooked' example.

Which is the correct way of doing this?

The MWE is as follows.

\documentclass{article}

\usepackage{booktabs} % For \toprule, \midrule and \bottomrule
\usepackage{siunitx} % Formats the units and values
\usepackage{pgfplotstable} % Generates table from .csv
\pgfplotsset{compat=1.11}% supress warning

% Setup siunitx:
\sisetup{
  round-mode          = places, % Rounds numbers
  round-precision     = 2, % to 2 places
}

\begin{document}

\begin{table}[h!]
  \begin{center}
    \caption{Autogenerated table from .csv file.}
    \label{table1}
    \pgfplotstabletypeset[
      multicolumn names, % allows to have multicolumn names
      col sep=comma, % the seperator in our .csv file
      string type, % Added in hopes of enabling alphabetic input.
      display columns/0/.style={
                column name=$Value 1$, % name of first column
                column type={S},string type},  % use siunitx for formatting
      display columns/1/.style={
                column name=$Value 2$,
                column type={S},string type},
      every head row/.style={
                before row={\toprule}, % have a rule at top
                after row={
                        \si{\ampere} & \si{\volt}\\ % the units seperated by &
                        \midrule} % rule under units
                        },
                every last row/.style={after row=\bottomrule}, % rule at bottom
    ]{table.csv} % filename/path to file
  \end{center}
\end{table}

\end{document} 

My (working) csv input is:

Input file (csv)

Its output is:

enter image description here

And I would like to input:

Desired input

And get an analogous output. i.e. Words in the first column. However, in its current form, it returns the following error, as seen in he test.log.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! siunitx error: "duplicate-exponent-token"
! 
! Duplicate exponent marker token '\token_to_str:N e' in input.
! 
! See the siunitx documentation for further information.
! 
! For immediate help type H <return>.
!...............................................  

l.37     ]{table.csv}
                      % filename/path to file
? 
! Emergency stop.
!...............................................  

l.37     ]{table.csv}
                      % filename/path to file
|'''''''''''''''''''''''''''''''''''''''''''''''
| Only one exponent marker token can appear in a single number.
|...............................................
3

The problem is caused by your use of column type={S} for the first column: Using that column type will cause the content of the column to be parsed by siunitx, even if you specify string type afterwards. siunitx then stumbles on the line containing Three because it finds two e's, which it takes to be exponent markers. You can fix the problem by removing the column type={S}.

A couple more things: If you specify the column names manually (instead of taking them from the first row of your table), you should set header=false, otherwise the first line of data will be discarded.

To get proper alignment when using S columns, you should also specify the format of your numbers, in this case S[table-format=1.2e2 ] (one integer digit, two decimal digits, two exponent digits).

And lastly, to get italic text, never use $ (that's for maths mode and typesets the words as strings of variables, with awkward spacing), but rather use \textit.

\documentclass{article}

\usepackage{siunitx} % Formats the units and values
\usepackage{pgfplotstable} % Generates table from .csv
% Setup siunitx:
\sisetup{
  round-mode          = places, % Rounds numbers
  round-precision     = 2, % to 2 places
}

\begin{document}

    \pgfplotstabletypeset[
      multicolumn names,
      col sep=comma, % the seperator in our .csv file
      string type, % Added in hopes of enabling alphabetic input.
      display columns/0/.style={
                column name=\textit{Value 1}, % name of first column
                string type},  % use siunitx for formatting
      display columns/1/.style={
                column name=\textit{Value 2},
                column type={S[table-format=2.2e2]}}
    ]{
Two,2.00000E+015 
Three,2.000000E+015   
    }

\end{document} 
2
  • Thanks for the answer and all the suggestions! It works now. – Calculus Knight Nov 12 '15 at 11:23
  • I face the same problem@CalculusKnight. Kindly help – Ghulam Hafeez Apr 1 '20 at 3:43
0

\begin{table}[ht] \centering \caption{Evaluation of the proposed } \label{tab:Comput} \setlength{\tabcolsep}{0pt} \sisetup{round-mode=places, round-precision=2, table-format=1.2, } \begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} l *{5}{S} } \toprule & \multicolumn{5}{c}{Proposed and benchmark forecasting frameworks} \ \cmidrule{2-6} \thead{Months} & {\thead{FS-ANN\ Computational \efficiency}} & {\thead{Bi-level\ Computational \efficiency}} & {\thead{AFC-STLF\ Computational \efficiency}} & {\thead{MI-mEDE-ANN\ Computational\efficiency}} & {\thead{FS-FCRBM-GWDO \ Computational \efficiency}} \ \midrule Computational complexity (level) & Low & High & Moderate & High & Moderate \

\midrule %Avg.& 2.12 & 1.79 & 1.44 & 0.410\ \bottomrule \end{tabular*} \end{table}

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.