# How to pass in a ratio in fraction form (as opposed to decimal form) to table column definition?

My scenario is to pass in a ratio (in fractional form as opposed to decimal form) to each table column definition.

The following code cannot be compiled.

\documentclass{article}
\usepackage{pgf}
\usepackage{array}
\usepackage{longtable}

\newcommand{\ratio}[2]%
{%
\pgfmathsetmacro\temp{(#1)/(#2)}%
\temp%
}

\newcolumntype{A}[1]%
{%
>{}%
m{#1\linewidth-2\tabcolsep-2\arrayrulewidth}%
<{}%
}

\begin{document}
\ratio{1}{2}
\ratio{2}{5}

\begin{longtable}{|A{\ratio{1}{2}}|A{\ratio{1}{2}}|}\hline
A & B \tabularnewline\hline
A & B \tabularnewline\hline

\end{longtable}
\end{document}

-
Josephs solution works for me (after adding \end{longtable} to the code). – Caramdir Dec 28 '10 at 11:10
It seems to me that your #1\linewidth-2\tabcolsep-2\arrayrulewidth doesn't work. I'm not sure what's happening, but I get a "-2" in the table. – Hendrik Vogt Dec 28 '10 at 12:59
@Hendrik, you need calc.sty. – xport Dec 28 '10 at 13:03
Then why didn't you include \usepackage{calc} in your code above? I'd suggest you remove the whole piece starting from "Joseph's solution does not work"; his code does work. You just forgot \end{longtable} as the error message says and as Caramdir already noted. – Hendrik Vogt Dec 28 '10 at 13:18
@Hendrik, I did not read well. Yes. It works :-) We need copy to clipboard button. – xport Dec 28 '10 at 13:21

You cannot use \pgfmathsetratio here, as the arguments to the m box needs to expand to a number. Assuming you can use the e-TeX extensions then you can use an alternative definition:
\makeatletter