In my document I have a lot of images. Some are small icons and others are massive screenshots. The images should display either

  1. Their full resolution if the image is smaller than the width of the document, or
  2. Scaled down to the width of the document itself if the image is larger.

Right now each image is scaled to the width of the document regardless of how big the original image is. This means that the smaller images are blown up and pixelated, but the larger images look great.


  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Symbol 1 May 28 '15 at 15:58
  • Roughly speaking you can always have some \if-statements. However things become complicated if, say, your images are of different sizes and resolutions and you have a specific output device. For example, what do you expect if there is a 600dpi, 22cm-wide figure and your printer is of 600dpi? Probably you can fit that 22cm into \textwidth (about 14cm by default) but it would not be a good ratio. Setting scale=.5, at least in this case, might be better. – Symbol 1 May 28 '15 at 16:13

The easiest way is to use the adjustbox package with its export option so it passes its keys to \includegraphics then use max width=\textwidth

  • max width=\textwidth does not seems a right latex command. Did you mean \includegraphics[maxwidth=\textwidth]{figure.png}? – user Nov 17 '19 at 22:20
  • @user see adjustbox manual – David Carlisle Nov 17 '19 at 22:29
  • I used this answer: Includegraphics maximum width – user Nov 17 '19 at 22:39
  • @user yes as Martin says there, as he says in the adjustbox manual, the key is max width, I am not sure what you are asking in these comments? – David Carlisle Nov 17 '19 at 22:52
  • I am not sure what you are asking in these comments? On the first comment, I asked a question, you answered. End. On the second comment, I did not asked any questions, I just referenced/linked a answer I found related to this question. – user Nov 17 '19 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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