# Decimals in table don't align with dcolumn when bolded

I am making a table using booktabs and dcolumn. It works perfectly until I tried to bold one of the numbers and then the decimals won't read properly.

Are there any workaround here?

\documentclass{article}
\usepackage{booktabs,dcolumn}
\begin{document}
\newcolumntype{.}{D{.}{.}{-1}}
\begin{tabular}{l .}
\toprule
M & \multicolumn{1}{c}{N} \\
\midrule
5 & 12.0 \\
10 & \textbf{24.0}\\
\bottomrule
\end{tabular}
\end{document}


• I don't know with dcolumn, but in this answer there's a method with siunitx and its S-type column. – egreg Jun 10 '13 at 12:44

\textbf takes you out of math mode and gives you a text mode setting, which in principle is not using the math fonts at all (although in the computer modern setup digits and . do in fact come from the text roman font)

You would lose the alignment anyway as dcolumn needs to see the . at the top level not inside a group.

D is defined via \newcolumntype so you need to define a similar column say B that also inserts \boldmath

(Note your example generates several unrelated errors when run, please test before posting!)

\documentclass{article}

\usepackage{booktabs,dcolumn}
\begin{document}

\newcolumntype{.}{D{.}{.}{-1}}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{tabular}{l .}
\toprule
M & \multicolumn{1}{c}{N} \\
\midrule
5 & 12.0 \\
10 & \multicolumn{1}{B{.}{.}{-1}}{24.0}\\
\bottomrule
\end{tabular}
\end{document}


The . will be aligned exactly using the above, but the default bold digits are wider than the standard ones so alignment will be out. this may not matter if you only have one or two digits but to use the non-extended bold easiest is to define a version of \boldmath that uses b rather than bx.

\documentclass{article}

\usepackage{booktabs,dcolumn}
\DeclareMathVersion{nxbold}
\SetSymbolFont{operators}{nxbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters}  {nxbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols}  {nxbold}{OMS}{cmsy}{b}{n}

\begin{document}

\newcolumntype{.}{D{.}{.}{-1}}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{Z}[3]{>{\mathversion{nxbold}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{tabular}{l .}
\toprule
M & \multicolumn{1}{c}{N} \\
\midrule
5 & 11112.0 \\
10 & \multicolumn{1}{B{.}{.}{-1}}{11124.0}\\
19 & \multicolumn{1}{Z{.}{.}{-1}}{11124.0}\\
\bottomrule
\end{tabular}

\end{document}

• somehow i knew you'd be the one to answer this. why don't you add this situation to the dcolumn documentation? – barbara beeton Jun 10 '13 at 12:53
• @barbarabeeton I really wish I hadn't used an @ in \DC@ and \DC@end but it was a long time ago:-) I suspect that people (and google) are more likely to find it here than in the package doc but I may add something... – David Carlisle Jun 10 '13 at 13:27
• Thanks David Carlisle - that's really nice. Do you mind if I add it to the wikibook? I'd probably make it a non-booktabs version for simplicity - though personally I'm a (recent) convert to the booktabs style. – Chris H Jun 24 '13 at 9:55
• @ChrisH sure, see this link – David Carlisle Jun 24 '13 at 14:16

I got here but I just wanted to have the text bold but not increasing the width. I was not actually using dcolumn. In that case, via, you can do:

\usepackage{graphicx}
\newsavebox\CBox
\def\textBF#1{\sbox\CBox{#1}\resizebox{\wd\CBox}{\ht\CBox}{\textbf{#1}}}


And then use \textBF{24.0} instead of \textbf{24.0}.