我希望“置信限度”列中的数据与加/减符号对齐。以下是类似但不同的问题的链接在表中对齐 +- 符号。但是,此列的数据值的长度也不同。此外,虽然第一列中的数字按我希望的方式对齐,但我希望标题与它们对齐。
该表的当前样子如下:
这是我用来生成表的代码:
\documentclass[letterpaper,11pt,oneside, notitlepage]{article}% calls document type
\usepackage[usenames, dvipsnames, table, xcdraw]{xcolor}
\usepackage{booktabs}% table utilities
\usepackage{siunitx}% number and symbol alignment
\begin{document}
\begin{table}[htb]
\begin{tabular}{SSccc}
\toprule
\textbf{Mean} & \textbf{Confidence Limit} & \textbf{Year} & \textbf{Broodstock Source} & \textbf{Broodstock Type} \\ \hline
7816 & \num{+-1477} & 2016 & Oak Creek & Wild Captive \\
\rowcolor[HTML]{EFEFEF}
4996 & \num{+-262} & 2018 & Salt River & Wild Streamside \\
5646 & \num{+-328} & 2018 & Salt River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
1939 & \num{+-157} & 2018 & Verde River & Wild Streamside \\
2362 & \num{+-239} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
4012 & \num{+-671} & 2018 & Verde River & Wild Streamside \\
900 & \num{+-335} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
4820 & \num{+-47} & 2018 & Verde River & Wild Streamside \\
1008 & \num{+-134} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
419 & \num{+-427} & 2018 & Verde River & Wild Streamside \\
2460 & \num{+-290} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
1634 & \num{+-715} & 2018 & Verde River & Wild Streamside \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
任何帮助都将受到赞赏。
答案1
一些改进和代码简化:
\documentclass[letterpaper,11pt,oneside, notitlepage]{article}% calls document type
\usepackage[svgnames, dvipsnames, table, xcdraw]{xcolor}
\usepackage{booktabs}% table utilities
\usepackage{siunitx}% number and symbol alignment
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\renewcommand{\theadset}{\renewcommand{\arraystretch}{0.8}}
\begin{document}
\begin{table}[!htb]
\sisetup{table-number-alignment=center}
\rowcolors{3}{Gainsboro!50}{}
\begin{tabular}{S[table-format=4.0]S[table-format=\pm3, parse-numbers=false]ccc}
\Xhline{0.8pt}
{\thead[l]{Mean}} & {\thead{Confidence\\ Limit}} & \textbf{Year} & \thead{Broodstock \\Source} & \thead{Broodstock\\ Type} \\ \hline
7816 & \pm147\rlap7 & 2016 & Oak Creek & Wild Captive \\
4996 & \pm262 & 2018 & Salt River & Wild Streamside \\
5646 & \pm328 & 2018 & Salt River & Wild Streamside \\
1939 & \pm157 & 2018 & Verde River & Wild Streamside \\
2362 & \pm239 & 2018 & Verde River & Wild Streamside \\
4012 & \pm671 & 2018 & Verde River & Wild Streamside \\
900 & \pm335 & 2018 & Verde River & Wild Streamside \\
4820 & \pm47\hphantom{0} & 2018 & Verde River & Wild Streamside \\
1008 & \pm134 & 2018 & Verde River & Wild Streamside \\
419 & \pm427 & 2018 & Verde River & Wild Streamside \\
2460 & \pm290 & 2018 & Verde River & Wild Streamside \\
1634 & \pm715 & 2018 & Verde River & Wild Streamside \\ \Xhline{0.8pt}
\end{tabular}
\end{table}
\end{document}
答案2
一种临时方法是添加\hphantom
s。
\documentclass[letterpaper,11pt,oneside, notitlepage]{article}% calls document type
\usepackage[usenames, dvipsnames, table, xcdraw]{xcolor}
\usepackage{booktabs}% table utilities
\usepackage{siunitx}% number and symbol alignment
\begin{document}
\begin{table}[htb]
\begin{tabular}{SSccc}
\toprule
\textbf{Mean} & \textbf{Confidence Limit} & \textbf{Year} & \textbf{Broodstock Source} & \textbf{Broodstock Type} \\ \hline
7816 & \hphantom{7}\num{+-1477} & 2016 & Oak Creek & Wild Captive \\
\rowcolor[HTML]{EFEFEF}
4996 & \num{+-262} & 2018 & Salt River & Wild Streamside \\
5646 & \num{+-328} & 2018 & Salt River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
1939 & \num{+-157} & 2018 & Verde River & Wild Streamside \\
2362 & \num{+-239} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
4012 & \num{+-671} & 2018 & Verde River & Wild Streamside \\
900 & \num{+-335} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
4820 & \num{+-47}\hphantom{7} & 2018 & Verde River & Wild Streamside \\
1008 & \num{+-134} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
419 & \num{+-427} & 2018 & Verde River & Wild Streamside \\
2460 & \num{+-290} & 2018 & Verde River & Wild Streamside \\
\rowcolor[HTML]{EFEFEF}
1634 & \num{+-715} & 2018 & Verde River & Wild Streamside \\ \bottomrule
\end{tabular}
\end{table}
\end{document}