我想将数字四舍五入到小数点后 2 位。我尝试了以下代码,但它弄乱了标题。
平均能量损失
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\begin{document}
\begin{table}
\sisetup{round-mode=places}
\centering
\begin{tabular}{{|p{1.5cm}|c|p{1.5cm}|p{1.5cm}|p{1.6cm}|p{1.6cm}|}}
\hline
Molecule name & \# Structures & Mean $\Delta E$ (kcal/mol) & STD $\Delta E$ (kcal/mol) & Mean RMSD (\si{\angstrom}) & STD RMSD (\si{\angstrom}) \\
\hline
Propane & 10 & -5.532722 & 11.871219 & 0.525246 & 0.933334 \\
\hline
Pentane & 30 & -9.190216 & 2.529992 & 0.126386 & 0.047781 \\
\hline
\end{tabular}
\caption{somcap}
\end{table}
\end{document}
答案1
像这样?
您的S
列设置以及表格列规范不完整。您需要table-format
在每一S
列处指定、移动round-precision
到\sisetup
(对于较短的列规范),并\multicolumn
为第四列和第五列定义列标题:
\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{siunitx}
\usepackage{makecell} % new, needed at column headers
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c|}{\makecell{#2}}}
\begin{document}
\begin{table}
\sisetup{round-mode=places,
round-precision=2,
table-column-width=3em % for equal 4 and 5 column widths
}
\centering
\begin{tabular}{|p{1.5cm}|c
|S[table-format=-1.2]
|S[table-format=2.2]
|*{2}{S[table-format=1.2]|}
}
\hline
Molecule name
& \# Structures
& \mcc{Mean $\Delta E$\\ (kcal/mol)}
& \mcc[2]{Mean\\ RMSD (\si{\angstrom})}
& \mcc{STD\\ RMSD (\si{\angstrom})}
\\
\hline
Propane & 10 & -5.532722 & 11.871219 & 0.525246 & 0.933334 \\
\hline
Pentane & 30 & -9.190216 & 2.529992 & 0.126386 & 0.047781 \\
\hline
\end{tabular}
\caption{somcap}
\end{table}
\end{document}
附录:
同时 OP 更改了表格设计。新样式需要添加新的列标题并删除两列单元格的选项。由于现在更改了最小列宽,因此可以相应地进行更改:
\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{siunitx}
\usepackage{array, makecell}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c|}{\makecell{#2}}}
\begin{document}
\begin{table}
\sisetup{round-mode=places,
round-precision=2,
table-column-width=4em
}
\centering
\begin{tabular}{|m{1.5cm}|c
|S[table-format=-1.2]
|S[table-format=2.2]
|*{2}{S[table-format=1.2]|}
}
\hline
Molecule name
& \# Structures
& \mcc{Mean $\Delta E$\\ (kcal/mol)}
& \mcc{STD\\ $\Delta E$ (\si{\angstrom})}
& \mcc{Mean\\ RMSD (\si{\angstrom})}
& \mcc{STD\\ RMSD (\si{\angstrom})}
\\
\hline
Propane & 10 & -5.532722 & 11.871219 & 0.525246 & 0.933334 \\
\hline
Pentane & 30 & -9.190216 & 2.529992 & 0.126386 & 0.047781 \\
\hline
\end{tabular}
\caption{somcap}
\end{table}
\end{document}