I'm defining a new command that places two images one next to the other and I want to add an horizontal space between the two images which corresponds to one third of the space that remains blank. The command definition reads:

\hspace{(1-#2-#4)/3 \columnwidth }%
\end{center} }

I'm missing what I should use in order to get this operation solved. I've tried with \dimexpr but I always got errors. Is it not the right solution? When should I use \dimexpr and when \numexpr? The etex manual also was not so helpful for me.

  • 2
    Welcome! If you put an \hfill on each side and in the middle, it will put 1/3 the available space in each place.
    – cfr
    Commented Jan 16, 2016 at 22:43
  • Stick 2 \hfill in the middle.
    – cfr
    Commented Jan 16, 2016 at 22:51
  • Related (but no duplicate): tex.stackexchange.com/questions/236188/… Commented Jan 16, 2016 at 23:02

1 Answer 1


as cfr says, no calculation is necessary, but if #2\columnwidth works then #2 must be a factor but \numexpr needs an integer and \dimexpr needs a length so neither can calculate (1-#2-#4)


should do what you want.

In general you can do


which will stretch the glue in the ratio 1:2:3, the example above is of course equivalent to having each argument of \stretch be 1.

  • I was 8 seconds faster ;).
    – cfr
    Commented Jan 16, 2016 at 22:52
  • @cfr but I explained why an error for \dimexpr which took more than 8 sec:-) (also \hfill\box{} looks ...odd Commented Jan 16, 2016 at 22:53
  • Well, a complete example takes more time, too. You might be right about the box though.
    – cfr
    Commented Jan 16, 2016 at 22:55
  • 1
    @david23 tex douesn't have a floating point type just \count registers and \dimen and \skip registers which etex generalised to \numexpr and \glueexpr and \dimenexpr Commented Jan 17, 2016 at 10:27
  • 1
    @david23 don't see why you should get any underful boxes but blank lines are always significant they can not be used to just lay out the source file for cosmetic reasons, they are the instruction \par to end a paragraph. Commented Jan 17, 2016 at 10:28

You must log in to answer this question.

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