12

I use dcolumn to align (and modify) numerical entries in a table. When I try to change the font of a cell to mathbf it affects only the number before the decimal point. Assigning the mathbf to the numbers before and after the separator individually is not an option for me, because the number is read as one value from a csv file.

A similar effect also occurred when changing the color (which was already asked here). Here is my slightly modified example:

\documentclass[]{article}
\usepackage{dcolumn}
\begin{document}
\begin{tabular*}{\linewidth}{lD{,}{,}{1}}
text & 1,12\\
text & \mathbf 1,12\\       % only first part is bold
%text & \mathbf{1,12}\\     % leads to compilation error
text & \mathbf{1},\mathbf{12}\\ % not really nice and not usable for me
\end{tabular*}
\end{document}

Is there a similar solution to this problem?

Thank you very much!

David Carlisle
  • 757,742
Tim
  • 871
  • For reference, I'd recommend having a look at the S columntype from the siunitx package too – cmhughes Nov 27 '12 at 00:19
  • Thank you for the info. I do not use siunitx, because I also use other characters (placeholders that are replaced to spaces by dcolumn) as separators and I am not sure if siunitx can do this... – Tim Nov 27 '12 at 00:22

1 Answers1

12

D is defined by

\newcolumntype{D}[3]{>{\DC@{#1}{#2}{#3}}c<{\DC@end}}

so you can do a bold math version as

enter image description here

\documentclass[]{article}
\usepackage{dcolumn}
\showhyphens{musculoskeletal}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{document}
\noindent
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}lD{,}{,}{1}B{,}{,}{1}@{}}
text & 1,12&1,12\\
text & 1,12&1,12\\
text &\multicolumn{1}{B{,}{,}{1}}{1,12}&\multicolumn{1}{D{,}{,}{1}@{}}{1,12}\\
text & 1,12&1,12
\end{tabular*}
\end{document}
David Carlisle
  • 757,742
  • This works well for the whole column. I want to have to only use the bold version in some cells (although I failed to point this out in the question). Using multicol does not work (even with plain D), probably because of the extra {} around the value. – Tim Nov 27 '12 at 06:11
  • 1
    \multicolumn{1}{B}{3.5} should work to give a bold number in a non-bold columns. I will update the example – David Carlisle Nov 27 '12 at 09:48
  • I am not sure what I did different. Thank you! – Tim Nov 27 '12 at 09:59
  • 1
    For reference: \multicolumn seems to fail, if you do not use \makeatletter and \makeatother. – Tim Nov 27 '12 at 10:29
  • 2
    You need them around the definition of B otherwise \DC@ does not refer to the command named DC@ but to the undefined command named DC followed by the character @ and similarly \DC@end – David Carlisle Nov 27 '12 at 18:02
  • Curiosity: why the \showhyphens{musculoskeletal}? – Charles Stewart Jun 21 '13 at 05:46
  • @CharlesStewart good question:-) if you search this site for questions of a similar age you'll probably find I was working on a different MWE at the same time.... – David Carlisle Jun 21 '13 at 08:22
  • Also there is a better answer from me in a more recent question, I'll add a duplicate link at the top – David Carlisle Jun 21 '13 at 08:26
  • I don't think it works. OK, so that's a sweeping generalisation, but just by replacing the bold "1,12" with "1,1" you will see that the columns are no longer aligned on the comma. In fact, if you zoom in to the example above, you can see that the commas do not align perfectly between bold and non-bold rows in a particular column. After thinking about it, I'm not sure it can be done in this way - using multicolumn would naively appear to make a new, independent column, which dcolumn can only treat separately (though correctly for a column of 1 row). Maybe siunitx will do the job, but otherwis – Chris H Jun 20 '13 at 09:57