[Tex/LaTex] dcolumn with alignment to comma

dcolumn

this is supposed to be an easy question, but I didn't find a clear answer anywhere.

I want to use dcolumn with comma as a separator. However, I found different solutions and the manual is unclear to me. It says in D{>sep.tex<}{>sep.dvi<}{>decimal places<}, I have to choose ',' instead of '.' to achieve alignment to the comma. However I dont understand the difference between {>sep.tex<} and {>sep.dvi<}.

Also I found a solution where someone only used {>sep.dvi<} as a comma, whereas the manual suggests to use comma in both, {>sep.tex<} and {>sep.dvi<}.

Can someone explain the difference and tell me how to specify it correctly?

MWE simple as that:
\newcolumntype{G}{D..{2.1}} – where G currently aligns to the decimal point, not the comma, in case of 2 decimal places before the separator and 1 after.

Thanks.

Best Answer

Remarks

Let's look at the definition \newcolumntype{>name<}{D{>sep.tex<}{>sep.dvi<}{>decimal places<}}:

  1. >name< is the name for your new column, limited to one character.
  2. >sep.tex< is the character, which is used for alignment in the TeX code.
  3. >sep.dvi< is the character, which will substitute the >sep.tex<-character in the output (in most cases identical to >sep.tex<, because we only use alignment).
  4. >decimal places< is either -1 for auto detect or pre comma places.post comma places.

Example

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikzsymbols}% for \Smiley
\usepackage{dcolumn}
\newcolumntype{G}{D{,}{\Smiley}{2.1}}
\begin{document}
\begin{tabular}{|G|G|}
    10,2 & 5,3 \\
    8,1 & 10,2 \\
    4,4 & 8,1 \\
    8.1 & 10.22 \\ % <-- broken by purpose
    3,4 & 8,5 \\
\end{tabular}
\end{document}

Output

enter image description here

Related Question