4

I would like the data in the "Confidence Limit" column to align on the plus/minus symbol. Here is a link to a similar but different question Aligning +- sign in table. However, the values in my data for this column also vary in length. Additionally, while the numbers in the first column are aligned the way I would like, I wish the header was aligned to them.

Here is what the table currently looks like:

enter image description here

This is the code I used to generate the table:

\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}

Any help is appreciated.

2 Answers 2

2

Some improvements and code simplification:

\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} 

enter image description here

2
  • Any insight on how left align that first columns header? Commented Mar 8, 2019 at 14:19
  • 1
    Yes. Specify the number of digits in the preamble and replace \textbf{Mean} with {\thead[l]{Mean}}. Please see the updated code.
    – Bernard
    Commented Mar 8, 2019 at 14:36
4

An ad hoc way is to add \hphantoms.

\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}

enter image description here

1
  • 2
    There's a small white strip above the bottom rule.
    – Bernard
    Commented Mar 8, 2019 at 11:46

You must log in to answer this question.

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