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.

I need to color some text red (not color the cell background) in cell in a table to highlight it. The numbers in the column are aligned on the decimal using the dcolumn package. The problem is that

\color{red}{0.044} 

doesn't compile it's saying

} inserted at
\color{red}{0.
044}

and then saying that there is one too many }.

Can anyone help me with this?

share|improve this question
    
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Feb 6 '13 at 6:26
    
Also, \color{red} is a switch and does not take a paraeter, so you could try \color{red}0.044. –  Peter Grill Feb 6 '13 at 6:30
    
@PeterGrill you could try that (it won't work though) Or at least it will only color the first bit. –  David Carlisle Feb 6 '13 at 11:07
add comment

1 Answer

enter image description here

You just need to copy the definition of the D type and add colo(u)r:

\documentclass{article}

\usepackage{color,dcolumn}

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

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

\makeatother

\begin{document}

\begin{tabular}{E{red}..{-1}}
1.2\\
\multicolumn{1}{E{green}..{-1}}{-11.2}\\
1.333\\
\end{tabular}
\end{document}
share|improve this answer
    
I'd like to define a newcolumn type with one mandatory argument (the number of decimal places) and one optional argument (the text color) it aligns the period in the cell's contents on the decimal in the column. how would I do that. Also, can I have more than one \makeatletter ... \makeatother blocks –  Keith Feb 6 '13 at 22:51
    
you can have as many make ... as you want but you only ever need one, you can put ll redefinitions there (or better dont have one at all and put teh definitions in a local package you can reuse) –  David Carlisle Feb 6 '13 at 22:56
    
newcolumntypes (as defined in array package) don't have optional arguments so you have to make it mandatory, but that;s OK you can just use D or E{red} rather than D and D[red] –  David Carlisle Feb 6 '13 at 22:57
    
If I use D in the column specification, and E in the multicolumn with the cell I use E with line up on the decimals with the normal D cells in the same column also would \newcolumntype{E}[2]{>{\color{#2}\DC{.}{.}{#1}}c<{\DC@end}} be valid? –  Keith Feb 6 '13 at 23:22
    
I'm not sure I can parse that sentence but the answer is probably that yes it will work, the colour version doesn't affect the alignment so if you use the same alignment spec in the multicolumn{1} as in the preamble they will line up, or use the colour one in both with black as the color. yes your E spec looks OK to me except should be \DC@ not \DC (untested) –  David Carlisle Feb 6 '13 at 23:25
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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