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.

This question already has an answer here:

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!

share|improve this question

marked as duplicate by David Carlisle, T. Verron, Heiko Oberdiek, Martin Schröder, Thorsten Jun 21 '13 at 9:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
For reference, I'd recommend having a look at the S columntype from the siunitx package too –  cmhughes Nov 27 '12 at 0: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 0:22

1 Answer 1

up vote 11 down vote accepted

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}
share|improve this answer
    
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 6: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 9:48
    
I am not sure what I did different. Thank you! –  Tim Nov 27 '12 at 9:59
    
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.