As background, I was trying to write a macro that divides a page into columns given just a decimal scale factor. For example, given an input of .7 it should create columns of width .7*\textwidth and .3*\textwidth. Basically, I want to calculate (1-#1)*\textwidth.

It doesn't seem to be possible to use floating point values with \numexpr and \dimexpr, for example \dimexpr\textwidth*(1-#1) or \dimexpr\numexpr(1-#1)\textwidth. In this case there is a workaround, which is \dimexpr\textwidth-#1\textwidth. But it's easy to see how this would not work for more complex calculations.

Is there a way to do his using only (e)(La)TeX features? If not, what is the best alternative? Floating point calculations in LaTeX? gives some packages for floating point calculations but doesn't deal with lengths.

2 Answers 2


It's just a matter of importing a couple of expl3 kernel commands.



\newlength{\testlena} % for testing
\newlength{\testlenb} % for testing



\the\testlena\ --- \the\testlenb

\the\testlena\ --- \the\testlenb

\the\testlena\ --- \the\testlenb



For your application you just need \fpeval, but I showed also an example for \dimeval.

enter image description here

  • Beautiful, and no extra packages needed. Thanks! Commented Jun 28, 2022 at 23:59

As I was writing the question I found at least one possible solution using the package xintexpr:


\relax is needed to terminate \xinttheexpr even though it wouldn't be needed for \numexpr in this context. It's not clear to me why \xinttheexpr must be used rather than the simpler \xintexpr.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .