I know this is an old thread, but I'd like to offer an alternative solution that solves a recurring problem raised by the previous answers. The previous answers all require a restatement of the column format parameters (e.g., \multicolumn{1}{B{.}{.}{-1}}{...}
) in each bold cell. This becomes extremely cumbersome in large data tables, since changing the max decimal places for a column then requires finding every bold cell in the column and changing them all accordingly.
The following alternative solution creates a simpler, no-parameter \boldcell
macro that changes the font to bold in a cell without needing to restate any column format parameters.
\documentclass{article}
\usepackage{booktabs,dcolumn}
\newcommand\theDC{}
\newcommand\boldcell{\relax\ifmmode$\egroup\fi\bfseries\boldmath\theDC}
\makeatletter
\newcolumntype{E}[3]{>{\def\theDC{\DC@{#1}{#2}{#3}}\theDC}c<{\DC@end}}
\makeatother
\newcolumntype{.}{E{.}{.}{-1}}
\begin{document}
\begin{tabular}{l .}
\toprule
M & \multicolumn{1}{c}{N} \\
\midrule
5 & 12.0 \\
10 & \boldcell 24.0 \\
\bottomrule
\end{tabular}
\end{document}
This works by creating a new column type E
that is just like D
except that it saves the column format parameters, which can then be recalled by \boldcell
.
Getting a \boldcell
implementation that works is trickier than it may seem because we can't use \multicolumn
, since it replaces the column formatting before the original format parameters can be saved. To avoid this, \boldcell
instead aborts the in-progress \DC@
before it creates any output and then restarts it with bold font. This way the original parameters get saved and can be automatically reused during the restart.
One can replace \boldmath
in the above to use a different bold math font if desired (see other answers).
dcolumn
, but in this answer there's a method withsiunitx
and itsS
-type column.