16

I want to highlight some numbers in a table using \bf{}. However, the bold numbers also get wider but I want them to neatly line up with the rest. How can I avoid this?

Peter Grill
  • 223,288
Peter
  • 163

1 Answers1

18

You can use "non extended bold face":

\documentclass{article}
\usepackage{booktabs}

\newcommand{\bftab}{\fontseries{b}\selectfont}

\begin{document}
\begin{tabular}{lc}
\toprule
Class & Value \\
\midrule
A & 10 \\
B & 12 \\
C & \bftab 13 \\
D & 11 \\
\bottomrule
\end{tabular}
\end{document}

enter image description here

Note. From your question I gather that you're using \bf{13} or something like that. It's wrong for two reasons:

  1. \bf is an obsolete command;
  2. it is not a command with argument.

Use \textbf{13} or {\bfseries 13} (the former is preferred for single snippets of boldface text, the latter is for longer passages or in the definition of environments).

egreg
  • 1,121,712
  • 1
    Note that whether this works seems to depend on the font and the fontsize. E.g. scriptsize cmr b is too narrow (while bx is still too wide, and bsx doesn't exist). – oulenz Jun 12 '20 at 13:18
  • what if I want to use bold for multiple chunks of text? For example, \bftab 0.673 $\pm$ 0.017 only makes 0.017 bold. While {\bftab 0.673 $\pm$ 0.017} works but alters the alignment of the cell. – Luca Clissa Aug 06 '23 at 10:30
  • 1
    @LucaClissa You should use siunitx features, in this case those related to uncertainty. – egreg Aug 06 '23 at 12:42
  • @egreg Can you elaborate more? I can open a new post if you think it's better – Luca Clissa Aug 07 '23 at 08:54
  • @LucaClissa Did you look for “uncertainty” in the manual of siunitx? – egreg Aug 07 '23 at 09:52
  • @egreg I tried to, but it didn't help. Anyway I found out I can use \bftab in conjunction with detect-weight option to make the whole thing (number \pm uncertainty) bold. Specifically, I used something like \begin{tabular}{@{} l *{5}{S[detect-weight]} @{}} in the column definition and then bftab in the cell I wanted to make bold. – Luca Clissa Aug 08 '23 at 07:31