How to pass in a ratio of 4/15 (instead of its approximated decimal form of 0.266) to table definition.

Final solution can be seen here.

I need one more vote to close this topic.

  • But, if you have another solution, welcome!
    – xport
    Dec 26 '10 at 18:52
  • Unfortunately, the \ratio above cannot accept dimensionless values such as \ratio{4}{15}. :-(
    – xport
    Dec 26 '10 at 19:30
  • 2
    If you want some overkill, you could use pgfmathparse.
    – Caramdir
    Dec 26 '10 at 19:33
  • @Caramdir, I will revisit this tomorrow. Thank you for commenting.
    – xport
    Dec 26 '10 at 19:44
  • @xport: Only the first comment in your \ratio macro is necessary.
    – TH.
    Dec 28 '10 at 9:11

If you want more accurate calculations use the fp package.

For example using the fp package as shown below you get 0.999999999999999998 rather than 0.998.



No need for any manual calculations!

You can use it in a tabular as follows (remember it creates variable names on the fly)




\begin{tabular}{|p{\columni cm}|p{\columnii cm}|}
a & b \\
c & d \\


  • @Yiannis, thanks for answering. It is useful.
    – xport
    Dec 27 '10 at 1:41
  • @Yiannis, how to define a newcommand with 2 inputs and produces the ratio between the inputs? Internally the newcommand use \FPdiv of course. I don't understand the manual of fp.sty. It is very short and difficult to understand.
    – xport
    Dec 27 '10 at 2:27
  • @xport \def\division#1#2{ \FPdiv\result{#1}{#2} \result } \division{2}{9999} Dec 27 '10 at 3:51
  • @Yiannis, please kindly see again my last update above.
    – xport
    Dec 27 '10 at 5:05
  • @xport: I didn't check for sure, but the problem is that the \FP macros are not expandable. You're going to have to do the division before you need to use the result in an expandable manner.
    – TH.
    Dec 27 '10 at 12:02

I cannot see a gap with a zoom of 400% ...




  • because you took more accurate decimal numbers. You lost only 0.0001 in total. :-)
    – xport
    Dec 26 '10 at 19:00
  • 1
    even though there is no gap by taking more accurate decimal ratios, doing conversion manually is tedious.
    – xport
    Dec 26 '10 at 19:09

See Joseph's solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.