2

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.

21
  • 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
4

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}

7
  • @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
1

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}
2
  • 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
0

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.