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.

I want to store a ratio value in a command, e.g. \newcommand{\ratio}{0.7}, and then use it in recalculating a length, e.g. \setlength{\somelength}{\ratio*\width}.

Using lengths to store the ratio doesn't seem to work as it requires a unit (but ratios are unitless). I've also tried using calc but I can't seem to get it to work.

How should I go about this?

EDIT: Minimal example:

\documentclass{standalone}

\newcommand{\widthRatio}{0.7}
\newlength{\newWidth}
\setlength{\newWidth}{\widthRatio*\textwidth} % Doesn't compile

\begin{document}
\end{document}
share|improve this question
5  
If \width is a register like \textwidth then your code would work if you omit * –  David Carlisle Mar 13 '13 at 14:39
    
With code samples of your unsuccesful attempts, it would be better, and you would likely get a full answer instead of a one liner from @David. –  tohecz Mar 13 '13 at 14:49
    
@tohecz: There, minimal example added. =) –  gablin Mar 14 '13 at 7:47
    
@DavidCarlisle: Cool, didn't know about that! Could you please add that as an answer so that I can accept it? –  gablin Mar 14 '13 at 7:47

1 Answer 1

up vote 2 down vote accepted

As \textwidth is a dimen register if you omit the * it is already correct syntax.

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.