4

Having a table with numeric values, I want to achieve:

  1. Automatically grouping digits into blocks of three
  2. Highlight some cells in bold

However, no alignment is needed. To achieve the first, I use the S column of siunitx, combined with the table-parse-only package option to turn off alignment.

Now I'm struggeling with the second point. The solution from siunitx: Bold single numeric cells proposes the following:

\usepackage{etoolbox,siunitx}
\robustify\bfseries
\sisetup{detect-weight=true,detect-inline-weight=math}

\begin{document}
\begin{tabular}{SS}
1111.11 & \bfseries 1111.11 \\
\end{tabular}
\end{document}

But as soon as I add the table-parse-only option, the second cell isn't bold anymore. I could also write:

1111.11 & {\bfseries 1111.11} \\

Then the second cell is bold, but automatic grouping is turned off.

How can I simply create numeric table with automatic grouping and no alignment, that allows me to highlight some cells in bold?

2
  • 1
    How big is your table? Can't you just use an l column and do \bfseries \num{11111.11}? And why do you want to get rid of the alignment? That's the coolest part of the whole thing...
    – LaRiFaRi
    Aug 21, 2015 at 10:29
  • The size is not important. No matter how big it is, I can always write a short script that inserts the additional code. However, I'm looking for a clean und beautiful solution, and inserting redundant code is ugly. - And I don't want alignment, because it requires me to specify the column width explicitly. I don't want to do this. The columns contain numbers of different length, and I want the column width to be chosen automatically such that it fits the numbers. Aug 23, 2015 at 22:59

1 Answer 1

2

For one-off cells you can always use a \multicolumn command such as

\multicolumn{1}{c}{\bfseries \num{11111.11}}

This can be packaged in to a macro \tbnum for convenience:

\newcommand{\tbnum}[1]{\multicolumn{1}{c}{\bfseries \num{#1}}}

Sample output

\documentclass{article}

\usepackage{etoolbox,siunitx}
\robustify\bfseries
\sisetup{table-parse-only,detect-weight=true,detect-inline-weight=text}

\newcommand{\tbnum}[1]{\multicolumn{1}{c}{\bfseries \num{#1}}}

\begin{document}

\begin{tabular}{SS}
  11111.11 & \multicolumn{1}{c}{\bfseries \num{11111.11}} \\
  11111.11 & \tbnum{11111.11} \\
\end{tabular}

\end{document}
3
  • Is there any possibility to extend your solution so that it works with techniques that allow us to highlight a whole row in bold (e.g. texfaq.org/FAQ-wholerow)? I want to avoid adding \tbnum{x} to each individual cell, and write \rowstyle{\bfseries} only at the beginning of the row. Jul 2, 2019 at 11:40
  • It doesn't work for me, I have started a new question: tex.stackexchange.com/questions/573658/…
    – yannis
    Dec 5, 2020 at 0:05
  • @yannis The OP specifically asked for turning off alignment. Dec 5, 2020 at 10:05

You must log in to answer this question.

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