\includegraphics produces boxes whose witdth and height are about 0.5pt off:


Is there a version of \includegraphics which can resize with higher precision? I'm using pdflatex.

FYI There is no rounding error if only width= or height= is specified, but if both are specified, then both are rounded incorrectly.

  • 1
    Didn't you write a package once that promised higher precision? Commented Dec 11, 2011 at 21:33
  • 1
    I think the difference here stems from the fact that graphicx (or ultimately graphics) scales items in big points (bp) rather than some smaller length unit.
    – Werner
    Commented Dec 11, 2011 at 21:38
  • @Werner: This is usually an issue but AFAIK its an rounding issue in the graphic/x code. Commented Dec 11, 2011 at 21:51
  • @Martin Schröder: I can't use my package right now, because it doesn't support all options of \includegraphics I need.
    – pts
    Commented Dec 12, 2011 at 22:51

2 Answers 2


The height and width options and the related \resizebox actually calculate a scale factor and then use some internal form of \scalebox to do the scaling. Because this calculation requires a division (which is implemented using a loop in graphic/x) a numeric error is introduced. The size of the error depends on the original and requested size. If the scale factor is an integer there is no error. The equation is (IIRC) like follows:

(requested size / original size) * original size ~ requested size

Where the (..) factor suffers unfortunately from the limited resolution of TeX.
(~ = approximately)

Also the actually scaling is done by the driver or the output format itself, i.e. the image is added to the PDF as it is and the viewer does the scaling as ordered. I don't think you can get a smaller error. I myself tried other ways for the division and didn't got a better precision.

In order to have an official size in TeX a box with the given size is inserted. Unfortunately graphic/x takes the calculated scale factor to produce the box, not the requested width and height. It would be possible to rewrite the code to do it differently, then the image should still have the same size as before in the PDF viewer but the official TeX size would be "correct", i.e. as requested. This could be done by simple setting the width and height explicitly to the requested sizes. I did some research and work in this direction for my adjustbox package, which is based on graphicx. However, I didn't dared patching graphics/x so far to not risk any hidden comparabilities etc.

You could also check the PDF standard if it is possible to include the scaled image with the given requested size (converted to bp) instead of a scale factor, and then rewrite the pdftex driver accordantly.


The expl3 'native' driver code offers one way to get higher precision. At present, that code doesn't have graphics inclusion, so the set up requires first inclusion of the image unscaled into a box, followed by a scaling:

  \cs_new_eq:NN \ResizeBox \box_resize_to_wd_and_ht_plus_dp:Nnn
% Image from mwe bundle

Here, I get a final width of exactly 345 pt and height of exactly 550 pt using the latest expl3 code. As Martin observes in his answer, resizing an item is done by the driver itself as a scaling (\pdfsetmatrix primitive with a recent-ish pdfTeX). Thus the final size is the closes that TeX can get to the scale factor times the original size, rather than being the absolute value given. We've recently adjusted our code so that this should not show up in most cases: you'll get exactly the size requested.

  • Will the native-drivers option be set by default some day in the future? Since a number of CTAN packages already build on expl3, one of them loading expl3 with this option while others not may cause an option-clash error.
    – AlexG
    Commented Jan 30, 2015 at 7:51
  • 1
    @AlexG It is set by default with the latest release
    – Joseph Wright
    Commented Jan 30, 2015 at 8:25
  • 1
    @AlexG BTW, I've updated CTAN with the adjusted code here, so it should be generally available within a couple of days
    – Joseph Wright
    Commented Jan 30, 2015 at 8:29

You must log in to answer this question.

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