Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
1  
I don't have enough rep to do anything other than leave a new answer, so I apologize if this is out of place. If somebody with more rep wants to repost this as a comment on Joseph's post, please feel free. I ran into trouble using the solution posted by Joseph as-is. However, siunitx provides a workaround for the problem of mathptmx not providing bold math mode numerals - you can specify mode=text in addition to your other sisetup options to –  user31088 May 22 '13 at 15:31
add comment

1 Answer

up vote 11 down vote accepted

The recommended way to do this is to use \bfseries and make it robust using etoolbox

\documentclass{standalone}
\usepackage{etoolbox,siunitx}
\robustify\bfseries
\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.

share|improve this answer
    
Thanks, but with your code I get no bold formatting (see edits to question). –  badroit Aug 7 '12 at 20:54
1  
@badroit It works for me as written. Did you make any alterations? If not, can you add \listfiles to your input and report the result? –  Joseph Wright Aug 7 '12 at 21:03
1  
@JosephWright -- there seems to be something weird going on: Your method works for C Modern, L Modern, mathpazo, txfonts, and the newtxtext/newtxmath font groups, but not if the mathptmx (Times Roman for both text&math) package is loaded; in the latter case, the \bfseries command simply doesn't seem to have an effect. –  Mico Aug 7 '12 at 23:51
1  
@Mico That depends on how the fonts are set up, and in particular if the font provides proper access to bold math mode numerals via \boldmath. If you try this with mathptmx, it does not, hence the issue. –  Joseph Wright Aug 8 '12 at 7:03
1  
@badroit You have v2.3h, while I have the current release (v2.5g). While I cannot find it in the log, I do remember there were some issues with bold in table cells with some versions, and I have a feeling you are seeing a bug which is now fixed. –  Joseph Wright Aug 8 '12 at 7:10
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.