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 want to align decimal values in a table with some values printed in bold. Just by itself, this is no problem. We can use the siunitx package and \robustify\bfseries to do the trick as described, e.g., in siunitx: Bold single numeric cells.

However, I would like to keep the decimal point of the bold values in normal weight. This gives an overall more visually pleasing impression. So far I use a crude workaround (r@{.}l) in which integer and decimal parts are their own column.

Is there a possibility to arrive at my desired formatting with siunitx or some other package, or do I have to continue using my crude workaround?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Package siunitx provides option output-decimal-marker that can be used to set a decimal separator that is not bold. The example is based on this answer of Joseph Wright for the cited question.

\documentclass{standalone}
\usepackage{etoolbox,siunitx}

\newrobustcmd*{\bftabnum}{%
  \bfseries
  \sisetup{output-decimal-marker={\textmd{.}}}%
}

\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 & \bftabnum 11.1\\
  \bftabnum 2.1 & 1.94 \\
\end{tabular}

\end{document}

Result

share|improve this answer
    
Thank you for the solution. –  shiin Jan 29 at 14:31
    
Why redoing the setting at each call? –  egreg Jan 29 at 14:31
    
@egreg: Trying to be defensive. The OP has to mark the bold numbers in the table anyway. Therefore the setup is put in this markup macro \bftabnum. There might be other contexts, where unaligned numbers might be wanted without having a different font for the decimal separator (e.g. a number in a bold text in a p column or whatever). –  Heiko Oberdiek Jan 29 at 14:36
    
The instruction \sisetup does local settings. It's sufficient to localize it in the corresponding table environment. –  egreg Jan 29 at 14:39

Tell siunitx that your decimal point must be in the normal font. Above is the example in the linked message, below I added the setting for the period in normal font.

\documentclass[varwidth]{standalone}
\usepackage{etoolbox,siunitx,booktabs}
\robustify\bfseries
\begin{document}

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

\sisetup{
  detect-weight=true,
  detect-inline-weight=math,
  output-decimal-marker=\textnormal{.},
}
\begin{tabular}{S[table-format=1.2]S[table-format=2.2]}
\toprule
{A} & {B} \\
\midrule
1.01 & \bfseries 11.1\\
\bfseries 2.1 & 1.94 \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

share|improve this answer
    
great, thanks for the solution –  shiin Jan 29 at 14:30

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.