4

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}
2
  • 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.
    – jub0bs
    Commented May 11, 2014 at 17:59
  • Thank you @Jubobs, I have updated my post to include the necessary code.
    – raindrop
    Commented May 11, 2014 at 18:02

2 Answers 2

5

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

3

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}

You must log in to answer this question.

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