1

I am trying to make some cells bold. Some of the cells may have a trailing asterisk which should also be taken into account. I tried the recommendation in this post, but that does not seem to help much in my case. I am not sure what I am doing wrong here.

As an additional question, I am also wondering whether I can use \sisetup{} for every individual table with different values every time, or whether this command sets the global values. If it sets the global values, how can I make sure that the settings only apply to that table?

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\usepackage{etoolbox} \robustify\bfseries

\begin{document}

\begin{table}[hb] \begin{threeparttable} \sisetup{table-format=.4,add-integer-zero=false,detect-weight=true,detect-inline-weight=math} \begin{tabular}{lSSS|SSSS|SS} \midrule prof & -.1746* & .1606 & .1240 & .0556 & .1498* & .2858 * & .1204 & .1545* & .1842* \ stud & .0005 & \bfseries{.1918} & .0206 & .0281 & .0647 & \bfseries{.3651} & -.0312 & \bfseries{.1778} & .0992 \end{tabular} \begin{tablenotes}[flushleft]\item* $p<.05$\end{tablenotes} \end{threeparttable} \end{table} \end{document}

Bernard
  • 271,350

1 Answers1

1

enter image description here

(I didn't bother with vertical lines)

In comparison to your MWE the following changes were done in the following MWE:

  • defined is robust command for command \B which is used instead of \bfseries
  • added is mode=text
  • redefined is table-format
  • added is space for *
\documentclass{book}
\usepackage{siunitx}
\usepackage{booktabs, tabularx, threeparttable}

\usepackage{etoolbox} \newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries} %

\begin{document} \begin{table}[hb] \sisetup{detect-weight, % <-- mode=text, % <-- table-format=-0.4, % <--
add-integer-zero=false, table-space-text-post={} % <-- } \begin{threeparttable} \begin{tabular}{l SSS|SSSS|SS} \toprule prof & -.1746 & .1606 & .1240 & .0556 & .1498* & .2858* & .1204 & .1545* & .1842* \ stud & .0005 &\B .1918 & .0206 & .0281 & .0647 &\B .3651* & -.0312 &\B .1778* & .0992 \ \bottomrule \end{tabular} \begin{tablenotes}[flushleft]\footnotesize \item[*] $p<.05$ \end{tablenotes} \end{threeparttable} \end{table} \end{document}

Zarko
  • 296,517
  • Thank you! Can you explain what these differences do? That way, I also learn what I am doing. Especially the use-case for mode=text I am wondering. – Bram Vanroy Jan 19 '21 at 14:35
  • @BramVanroy, the bes explanation you can find in siunitx package documentation :-). Also, you can comment some option and observe difference in result. Option mode=text make width of boldface numbers equal to width of the normal numbers (as used in text). – Zarko Jan 19 '21 at 14:45
  • Okay, great! A final question: can I use \sisetup in different places for different tables in my document? Or is it a global setup? – Bram Vanroy Jan 19 '21 at 14:46
  • 1
    @BramVanroy, if you put sisetup in preamble, than its settings are global, if you add in table than valid just for this table (and overwrite global settings). – Zarko Jan 19 '21 at 14:49