[Tex/LaTex] siunitx: Bold single numeric cells

boldmath-modesiunitxtables

I'm struggling to make a single numeric cell in an siunitx table bold. (A similar question for making a whole column bold is available here.)

I want to define a simple macro which I can set for the largest value in a row to make it bold.

A quick MWE:

\documentclass{standalone}
\usepackage{siunitx}
\usepackage{times}

\newcommand{\maxf}[1]{\ensuremath{\mathbf{#1}}}

\begin{document}


\begin{tabular}{S[table-format=1.2]S[table-format=2.2]}
\sisetup{detect-weight=true,detect-inline-weight=math}
{A} & {B} \\
1.01 & \maxf{11.1}\\
\maxf{2.1} & 1.94 \\
\end{tabular} 

\end{document}

(I use times because the math font (CM) and text font (Times) are slightly different in my document … this is just to highlight that need to format numbers in math mode.)

As I understand it, the following line should make siunitx listen for bold in math font.

\sisetup{detect-weight=true,detect-inline-weight=math}

But then I get the following:

bold not aligned

… the decimals are not aligned in either column.

If I instead try:

\newcommand{\maxf}[1]{\ensuremath{\boldmath #1}}

…with boldmath used in page 18 of the siunitx documentation (have never seen this command before), the numbers do not appear bold.


  • How can I define a macro (\maxf) to make single numeric cells bold in math mode and keep decimals aligned in siunitx?
  • If this is not possible or convenient, what highlighting options are available? For example, I notice that underlining using \newcommand{\maxf}[1]{\ensuremath{\underline{#1}} breaks decimal alignment.

EDIT, with Joseph's code below, I get the following (no bold):

enter image description here

EDIT3 This was because I had an older version of siunitx (v 2.3). I later upgraded to version 2.5 and it worked.


EDIT2 I solved my original highlighting needs by shading the cells of the max results instead.

\documentclass{standalone}
\usepackage{siunitx}
\usepackage{times}
\usepackage[table]{xcolor}

\newcommand{\maxf}[1]{{\cellcolor[gray]{0.8}} #1}

\begin{document}


\begin{tabular}{S[table-format=1.2]S[table-format=2.2]}
\sisetup{detect-weight=true,detect-inline-weight=math}
{A} & {B} \\
1.01 & \maxf{11.1}\\
\maxf{2.1} & 1.94 \\
\end{tabular} 

\end{document}

enter image description here

Best Answer

The recommended way to do this is to use \bfseries

\documentclass{standalone}
\usepackage{siunitx}
\begin{document}

\sisetup{detect-weight=true,detect-inline-weight=math}
\begin{tabular}{S[table-format=1.2]S[table-format=2.2]}
{A} & {B} \\
1.01 & \bfseries 11.1\\
\bfseries 2.1 & 1.94 \\
\end{tabular} 

\end{document}

Note that you need to set up the font detected outside of the first cell, as table cells form groups.