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.

The table comes from the excellent answer of Philippe Goutet about this question :

\documentclass[a4paper,12pt]{article}      
\usepackage{array,booktabs} % I add booktabs AM
\usepackage[hmargin=2cm]{geometry}
\usepackage{xcolor}

\makeatletter
%http://groups.google.com/group/comp.text.tex/msg/7e812e5d6e67fcc5
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\begin{document}  % 

\begin{center}\begin{tabular}  % Philippe Goutet 
  {>{\def\colunit{pt}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{mm}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{cm}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{ex}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{em}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{bp}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{dd}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{pc}}l<{\convertto{\rowunit}{1\colunit}}
   >{\def\colunit{in}}l<{\convertto{\rowunit}{1\colunit}}
   >{\bfseries}l}
\multicolumn{1}{l}{\bfseries 1pt} & \multicolumn{1}{l}{\bfseries 1mm} &         
\multicolumn{1}{l}{\bfseries 1cm} & \multicolumn{1}{l}{\bfseries 1ex} &   
\multicolumn{1}{l}{\bfseries 1em} & \multicolumn{1}{l}{\bfseries 1bp} & 
\multicolumn{1}{l}{\bfseries 1dd} & \multicolumn{1}{l}{\bfseries 1pc} & 
\multicolumn{1}{l}{\bfseries 1in} & \\
\gdef\rowunit{pt} & & & & & & & & & \rowunit\\
\gdef\rowunit{mm} & & & & & & & & & \rowunit\\
\gdef\rowunit{cm} & & & & & & & & & \rowunit\\
\gdef\rowunit{ex} & & & & & & & & & \rowunit\\
\gdef\rowunit{em} & & & & & & & & & \rowunit\\
\gdef\rowunit{bp} & & & & & & & & & \rowunit\\
\gdef\rowunit{dd} & & & & & & & & & \rowunit\\
\gdef\rowunit{pc} & & & & & & & & & \rowunit\\
\gdef\rowunit{in} & & & & & & & & & \rowunit\\
\end{tabular}\end{center}

\end{document}

I would like to align the decimal separator in each column. I try with numprint and siunitx. I know the trick r@{.}l but here ... I'm waiting to see ...

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted
\usepackage{dcolumn}
\newcolumntype{Z}[1]{D{.}{.}{2.5}<{\convertto{\rowunit}{1#1}}}
% for a comma as decimal separator use the following line
%\newcolumntype{Z}[1]{D{.}{,}{2.5}<{\convertto{\rowunit}{1#1}}}

Then the table can be input as

\begin{tabular}{Z{pt}Z{mm}Z{cm}Z{ex}Z{em}Z{bp}Z{dd}Z{pc}Z{in}>{\bfseries}l}
\multicolumn{1}{c}{\bfseries 1pt} & \multicolumn{1}{c}{\bfseries 1mm} &
\multicolumn{1}{c}{\bfseries 1cm} & \multicolumn{1}{c}{\bfseries 1ex} &
\multicolumn{1}{c}{\bfseries 1em} & \multicolumn{1}{c}{\bfseries 1bp} &
\multicolumn{1}{c}{\bfseries 1dd} & \multicolumn{1}{c}{\bfseries 1pc} &
\multicolumn{1}{c}{\bfseries 1in} & \\
\gdef\rowunit{pt} & & & & & & & & & \rowunit\\
\gdef\rowunit{mm} & & & & & & & & & \rowunit\\
\gdef\rowunit{cm} & & & & & & & & & \rowunit\\
\gdef\rowunit{ex} & & & & & & & & & \rowunit\\
\gdef\rowunit{em} & & & & & & & & & \rowunit\\
\gdef\rowunit{bp} & & & & & & & & & \rowunit\\
\gdef\rowunit{dd} & & & & & & & & & \rowunit\\
\gdef\rowunit{pc} & & & & & & & & & \rowunit\\
\gdef\rowunit{in} & & & & & & & & & \rowunit\\
\end{tabular}

enter image description here

In order to format the table using facilities of siunitx one can build it before typesetting:

\documentclass{article}
\usepackage{array,booktabs} % I add booktabs AM
\usepackage{siunitx}
\makeatletter
%http://groups.google.com/group/comp.text.tex/msg/7e812e5d6e67fcc5
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1\relax\relax}
\makeatother

\begin{document}

\begingroup
\def\arow#1{
  \convertto{#1}{1pt}&
  \convertto{#1}{1mm}&
  \convertto{#1}{1cm}&
  \convertto{#1}{1ex}&
  \convertto{#1}{1em}&
  \convertto{#1}{1bp}&
  \convertto{#1}{1dd}&
  \convertto{#1}{1pc}&
  \convertto{#1}{1in}&
  #1}
\edef\rows{%
  \unexpanded{%
    \begin{tabular}{*{9}{S[table-format=2.5]}>{\bfseries}l}
    \multicolumn{1}{c}{\bfseries 1pt} & \multicolumn{1}{c}{\bfseries 1mm} &         
    \multicolumn{1}{c}{\bfseries 1cm} & \multicolumn{1}{c}{\bfseries 1ex} &
    \multicolumn{1}{c}{\bfseries 1em} & \multicolumn{1}{c}{\bfseries 1bp} &
    \multicolumn{1}{c}{\bfseries 1dd} & \multicolumn{1}{c}{\bfseries 1pc} &
    \multicolumn{1}{c}{\bfseries 1in} & \\
  }
  \arow{pt}\noexpand\\
  \arow{mm}\noexpand\\
  \arow{cm}\noexpand\\
  \arow{ex}\noexpand\\
  \arow{em}\noexpand\\
  \arow{bp}\noexpand\\
  \arow{dd}\noexpand\\
  \arow{pc}\noexpand\\
  \arow{in}
  \noexpand\end{tabular}
}
\rows
\endgroup
\end{document}

enter image description here

Add to the S column specification all other options that are needed.

share|improve this answer
    
I saw some examples with dcolumn but I was not able to use it, so thanks !! Is it possible with numprint or siunitx? –  Alain Matthes Apr 22 '12 at 13:21
    
I get a new problem, how to write numbers with french format. –  Alain Matthes Apr 22 '12 at 15:19
    
@Altermundus With a comma? Just write d{.}{,}{2.5} instead of d{.}{.}{2.5} in the definition of the Z column type. –  egreg Apr 22 '12 at 15:20
    
No it's more complicated, I need to have a separator each three digits like 1 234,567 89. With numprint, it's easy because with frenchb and babel it's automatic I need to use \newcolumntype{d}{n{2}{5}} but I have a problem with `{\convertto{\rowunit}{1#1}} –  Alain Matthes Apr 22 '12 at 16:27
    
@Altermundus I don't think it's necessary in this case, but here's a solution –  egreg Apr 22 '12 at 18:09
show 2 more comments

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.