2

I would like to align numbers of the form 1/10 and 20/1,256 on the forward slash character. I have tried to use dcolumn, specifically the D command, but I clearly don't understand it:

\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcolumntype{ds}[1]{D{/}{/}{#1}}

When I try to use the new column specifier ds, e.g.

\begin{tabular}{l*{8}{|ds{3.6}}|} \hline

where the intention of the numbers is to specify up to 3 characters to the left of / and up to six to the right, I get

Package array Error: Illegal pream-token (3.6): `c' used.

and a lot of follow-on errors. It doesn't matter if I change the numbers.

Any help appreciated.

1 Answer 1

6

The problem seems to be that new column types can only have a single character as the notation. Then, you have two choices to achieve your desired result, which I call column types f and g, depending on whether you want the input syntax to use a . or a /. In either case, the typeset output uses a /.

\documentclass[]{article}
\usepackage{dcolumn}
\newcolumntype{f}[1]{D{.}{/}{#1}}
\newcolumntype{g}[1]{D{/}{/}{#1}}

\begin{document}
\begin{tabular}{|f{3.6}|f{3.6}|} \hline
3.46 & 23.5\\
43.5 & 4.78\\\hline
\end{tabular}

\begin{tabular}{|g{3.6}|g{3.6}|} \hline
3/46 & 23/5\\
43/5 & 4/78\\\hline
\end{tabular}
\end{document}

enter image description here

1
  • In hindsight the single character restriction should have been more obvious to me :-) Thanks!! Commented Jan 20 at 2:08

You must log in to answer this question.

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