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.

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.

share|improve this question
    
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

3 Answers 3

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.

\documentclass[11pt]{article} 
\usepackage{fp}
\begin{document}
  \parindent0pt
  \FPdiv\paramtwo{4}{15}
  \FPdiv\paramthree{2}{15}
  \FPmul\paramtemp{4}{\paramthree}
  \FPdiv\paramseven{3}{15}
  \FPadd\total{\paramseven}{\paramtemp}
  \FPadd\total{\total}{\paramtwo}

  \total
\end{document}

No need for any manual calculations!

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

\documentclass[11pt]{article} 
\usepackage{fp}

\FPdiv\columni{3.9999999}{3.8888888}
\FPdiv\columnii{1.11123456}{1.3999999}

\begin{document}

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

\end{document}

share|improve this answer
    
@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} –  Yiannis Lazarides 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% ...

\documentclass{article}
\parindent=0pt
\textwidth=15cm
\begin{document}

\rule{\textwidth}{5mm}

\rule{0.2667\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.2\textwidth}{5mm}

\end{document}
share|improve this answer
    
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
up vote 0 down vote accepted

See Joseph's solution.

share|improve this answer

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.