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

I would like to define a maximum height and a maximum width for an image at same time. I suppose there must be a package to do this, but actually I'm unable to find it...

share|improve this question
up vote 48 down vote accepted

You can use the keepaspectratio key and define your graphics as:


The MWE is as follows:


enter image description here

Experiment with images with different aspect ratios to see the effect.

share|improve this answer
(+1) MWE please :-D – kiss my armpit Mar 8 '12 at 13:30

If you load the package adjustbox with the export option, its keys are usable with \includegraphics: put the following in the preamble

\usepackage[export]{adjustbox} % loads also graphicx

and then use

\includegraphics[max height=<dimension>,max width=<dimension]{file}

In this way the image will be scaled at the maximum size so that its width and its height will not exceed the two stated dimensions and no distortion will be made.

share|improve this answer

You can use graphicx package as below.

\caption{Caption of the figure}

imagefile.pdf is the filename of your figure file and it can be .png, .jpg......etc.

share|improve this answer
Do you really need keepaspectratio when you only specify either width or height but not both? – kiss my armpit Mar 8 '12 at 13:36
When only width or height is specified the aspect ratio is automatically maintained by TeX. I have corrected the MWE accordingly. Thank you for noting it. Some how I over looked the same. – Harish Kumar Mar 8 '12 at 13:39
@HarishKumar This can lead to problems. Suppose you have an image equal to textwidth height but 1.5textheight it will disappear at the bottom and vice versa. Best to use both and keepaspectratio. – Yiannis Lazarides Mar 8 '12 at 15:46

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.