3

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.

4
  • 1
    \newcolumntype{G}{D{,}{,}{2.1}}? Jan 2, 2014 at 15:04
  • @HenriMenke I know this is what the manual suggests and it works, I have tested it. But what is the difference between the two arguments? In another thread I found sthg like \newcolumntype{G}[1]{D{.}{,}{2.1}}.
    – TomM
    Jan 2, 2014 at 15:06
  • 1
    The {>sep.tex<} is the one to match in the tex code and the {>sep.dvi<} is the one, which will appear in the document. Jan 2, 2014 at 15:09
  • @HenriMenke Ahh from your wording I think I got it. So {>sep.tex<} does the actual alignment, whereas {>sep.dvi<} is the visible outcome. If you want to make your comment an answer, I will accept it.
    – TomM
    Jan 2, 2014 at 15:15

1 Answer 1

7

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

1
  • What if I want to put a text in one of the rows and keep it centralized?
    – rph
    Nov 22, 2018 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .