[Tex/LaTex] Missing $ inserted

errorstables

When I use this code I get the ! Missing $ inserted.<inserted text>$ R and ! Missing $ inserted.<inserted text>$ \bottomrule errors on the 3rd and 4th last lines. How can I fix my code so that those errors go away?

\documentclass[letterpaper,12pt]{article}
\usepackage{tabularx,amsmath,boxedminipage,graphicx}
\usepackage[margin=1in,letterpaper]{geometry} % this shaves off default margins which are too big
\usepackage{cite}
\usepackage[final]{hyperref} % adds hyper links inside the generated pdf file
\usepackage{booktabs} % for better looking tables
\usepackage{siunitx}  % for units of measure and data in tables
\hypersetup{
    colorlinks=true,       % false: boxed links; true: colored links
    linkcolor=blue,          % color of internal links
    citecolor=blue,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=blue         
}

\begin{document}
\begin{tabular}{
 l % left aligned column
 l % left aligned column
 *{2}{S[table-format=4.0]} % three columns with numeric data       
}
\toprule
&\textbf{Method 1} & \textbf{Method 2}\\
\midrule
Run 1 & $345 \pm 1$ & $235 \pm 3$\\
Run 2 & $465 \pm 2$ & $342 \pm 4$\\
\bottomrule
\end{tabular}
\end{document}

Best Answer

First of all, you've added two l columns before the data columns, but as far as I can see you're using just one. Second, let siunitx do all the work in S columns, so don't add the dollar signs.

By default siunitx show the uncertainty as a number in parenthesis (see screenshot below). This can of course be changed, as you see in Svend Tveskæg's answer.

\documentclass[letterpaper,12pt]{article}
\usepackage{tabularx,amsmath,boxedminipage,graphicx}
\usepackage[margin=1in,letterpaper]{geometry} % this shaves off default margins which are too big
\usepackage{cite}
\usepackage[final]{hyperref} % adds hyper links inside the generated pdf file
\usepackage{booktabs} % for better looking tables
\usepackage{siunitx}  % for units of measure and data in tables
\hypersetup{
    colorlinks=true,       % false: boxed links; true: colored links
    linkcolor=blue,          % color of internal links
    citecolor=blue,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=blue         
}

\begin{document}
\begin{tabular}{
 l % left aligned column
 *{2}{S} % three columns with numeric data       
}
\toprule
&\textbf{Method 1} & \textbf{Method 2}\\
\midrule
Run 1 & 345 \pm 1 & 235 \pm 3\\
Run 2 & 465 \pm 2 & 342 \pm 4\\
\bottomrule
\end{tabular}
\end{document}

enter image description here

Related Question