当我使用此代码时,我在倒数第三行和第四行遇到了! Missing $ inserted.<inserted text>$ R
错误! Missing $ inserted.<inserted text>$ \bottomrule
。我该如何修复代码以消除这些错误?
\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}
答案1
首先,您l
在数据列前添加了两列,但据我所知,您只使用了一列。其次,让我们siunitx
在列中完成所有工作S
,因此不要添加美元符号。
默认情况下,siunitx
不确定性以括号中的数字显示(见下面的截图)。当然,这可以更改,如您在Svend Tveskæg 的回答。
\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}
答案2
这是一个可能的解决方案:
\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}
更新
这是使用强大的siunitx
包裹:
\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}