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:


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

  • 5
    If \width is a register like \textwidth then your code would work if you omit * Mar 13, 2013 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.
    – yo'
    Mar 13, 2013 at 14:49
  • @tohecz: There, minimal example added. =)
    – gablin
    Mar 14, 2013 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, 2013 at 7:47

1 Answer 1


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

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.