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

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?

share|improve this question

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

share|improve this answer
Ah!!!, You're right! Thank you so much! It was so simple... – user4876 Apr 13 '11 at 20:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.