When using images bigger than the text-area, I want to scale them but considering at the same time width and height. The problem happens to appear when both width and height are off limits. Here, I have to determine which one is the bigger, and then scale it, so the process will affect the other one too, and the image will be perfectly fitted in the text-area.

I've tried several ways to solve this. For example: (I'm using the calc package)




The result (always considering width and height bigger than text-area) are:

  • Case 1 : width > height | Works properly!

  • Case 2 : height > width | It doesn't show anything. No images included at all!

If you notice, I'm using width to scale because, if I use the scale attribute in \includegraphics, it gives an error.

I've tried many other ways, but no one gives me the result I want. I think the problem is the line where I perform the calculation:


If I replace that with, for example,


it shows reduced images maintaining the aspect ratio (so, I know it works... somewhat). Can anyone help me resolve this problem. I don't know what else to do, maybe use the xifthen package?

1 Answer 1


Ignoring the question you are asking, there is a simple solution to your actual problem: \includegraphics has an optional argument keepaspectratio, that (quoting the manual),

if set to true then specifying both width and height (or totalheight) does not distort the figure but scales such that neither of the specified dimensions is exceeded.

Thus, you can simply write

  • Ah!!!, You're right! Thank you so much! It was so simple...
    – user4876
    Apr 13, 2011 at 20:47

You must log in to answer this question.