Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. –  Jubobs May 11 at 17:59
    
Thank you @Jubobs, I have updated my post to include the necessary code. –  raindrop May 11 at 18:02

2 Answers 2

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

share|improve this answer

Here is a possible solution:

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{lcc}
\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}

output

Update

Here is another way of doing it using the powerful siunitx package:

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}
  \begin{tabular}{l *{2}{S[separate-uncertainty, table-format = 3, table-figures-uncertainty = 1]}}
   \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{table}

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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