TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to create a custom command which creates an underscore of a given length. However, this length should be the argument of the command multiplied be a floating point constant.

How can I multiply the argument of a command within the command's definition?

The code without the multiplication looks like this:

\newcommand{\utext}[2]{$\underset{\mbox{\tiny #1}}{\underline{\hspace{#2cm}}}$}

Instead of the \hspace of #2cm it should be something like (0.75 * #2)cm

share|improve this question
up vote 6 down vote accepted

There are two ways for solving the problem.

First (and recommended):


  $\underset{\mbox{\tiny #1}}{\underline{\hspace{#2\threequarters}}}$%

In this way, #2 can be any decimal number.

Second, trickier:

  $\underset{\mbox{\tiny #1}}{\underline{\hspace{0.75\dimexpr#2cm\relax}}}$%

Why do I recommend the first way? You can use \threequarters wherever you want and change its width by acting just in one place, instead of looking for 0.75 across your definitions.

However, also the second solution is "parametrisable", by doing


and using \hspace{\threequarterfactor\dimexpr#2cm\relax} in the definition. I still prefer reserving a length.

share|improve this answer
I suppose I'd better upvote this one for being even less wrong than my answer:-) – David Carlisle Apr 7 '13 at 10:34
Thank you. Both ways work perfectly! – Max Apr 7 '13 at 11:22

Since this is for a mathematical use, here is a command that can do the calculation with an accuracy of 18 decimal places.



  $\underset{\mbox{\tiny #1}}{\underline{\hspace{\result  cm}}}$}

\utext{test}{1.9809997889999999} \result

\utext{test}{1.9809997889999990} \result

enter image description here

share|improve this answer
Since I'm only calculating the length of the underscore, I won't need that much precision. This will be handy, when working with mathematical expressions though. Thanks – Max Apr 7 '13 at 11:25

Your Answer


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.