3

I am using the S-column type from the siunitx package to align numbers horizontally in a table, which works fine when typing numbers only. However, when I use math, I get the error

Missing $ inserted

even though the output is displayed correctly (presumably because LaTeX adds begin-math/end-math automatically - I am using Overleaf). Unfortunately, inserting $-signs around the expression does not solve the problem. Does anyone have an idea as to how I solve this problem?

Working example:

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{adjustbox}

\begin{document}

\begin{table}[h]
\centering
\begin{adjustbox}{max width=\textwidth}
    \begin{tabular}{lSS}
    \toprule
    \textbf{Parameter} & \textbf{Column1} &
    \multicolumn{1}{c}{\textbf{Column2}} 
        \\
    \midrule
a & 0.613 & 2.92\cdot 10^{-40}\\
b & 110.6 & $23.1\cdot 10^3$  \\
    \bottomrule
    \end{tabular}
    \end{adjustbox}
    % \caption{faulty table}
    \label{tab:}
\end{table}

\end{document}

Many thanks in advance!

0

1 Answer 1

5

You're using the wrong input format:

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{
  l
  S[table-format=3.3]
  S[table-format=2.2e-2]
}
\toprule
\textbf{Parameter} & {\textbf{Column1}} & {\textbf{Column2}}  \\
\midrule
a & 0.613 & 2.92e-40 \\
b & 110.6 & 23.1e3  \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

If you prefer the centered dot, add

\sisetup{
  exponent-product=\ensuremath{{}\cdot{}},
}

in the preamble.

enter image description here

3
  • What's the advantage of writing exponent-product=\ensuremath{{}\cdot{}} rather than, say, exponent-product=\cdot? I cannot spot a difference in the spacing around \cdot between \num[exponent-product=\ensuremath{{}\cdot{}}]{2.92e-40} and \num[exponent-product=\cdot]{2.92e-40}. Is there maybe another reason for using \ensuremath{{}\cdot{}}?
    – Mico
    Jan 4, 2019 at 14:38
  • @Mico This can be handy if numbers are processed in text mode.
    – egreg
    Jan 4, 2019 at 14:46
  • Ah, got it. E.g., it's useful if the package's detect-all switch is set.
    – Mico
    Jan 4, 2019 at 14:48

You must log in to answer this question.

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