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

For including graphics such as Matlab plots, I use \includegraphics from the graphicx package. Every time, I have to decide on some width and pass e.g. [width=180mm] to the inclusion command. This feels very arbitrary. How would I let LaTeX find the optimal width, assuming the graphic scales nicely without pixelation?

share|improve this question
How do you define “correct”? The same as \textwidth? – Caramdir Mar 6 '11 at 18:05
@Caramdir: I just want it to look nice. \textwidth would probably be fine. – Tim N Mar 6 '11 at 18:09
up vote 8 down vote accepted

Just like Caramdir suggests, use \hsize or \textwidth to scale your graphics to a consistent width:


You could also define a dimension for flexibility that you could later easily re-define to a different width:

\photowidth=0.8\textwidth % or \photowidth=180mm
share|improve this answer
Good answer, but \photowidth doesn't need to be a dimension but can also be a macro which holds e.g. 0.8\textwidth. This has the benefit (or drawback, depending on the point of view) that it adjusts if \textwidth changes afterwards, e.g. inside a minibox. – Martin Scharrer Mar 6 '11 at 18:47
@Martin: I assume the advantage of a dimension is that you would use it as in [width=0.5\photowidth] but this wouldn't be possible if it were defined as macro, right? But I can see your point, too -- a dimension is defined once. – Christian Lindig Mar 6 '11 at 18:52
You are right, but eTeX comes to the rescue: \def\photowidth{\dimexpr .8\textwidth\relax} gives you both the advantages! – Martin Scharrer Mar 6 '11 at 18:58
@Cristian Lindig: \newdimen is TeX command. How does it differ from \setlength? I prefer not to mix LaTeX and TeX commands just to keep my co-authors from asking the same question: what is the difference? – Igor Kotelnikov Mar 7 '11 at 2:56
@Igor You are right. To stay within LaTeX you can use \newlength{photowidth} to introduce the new dimension and use \setlength{photowidth}{180mm} to set it. – Christian Lindig Mar 7 '11 at 7:47

More elegant solution is to set desired width globally:


Setting width locally as shown by Christian overrides global keys.

share|improve this answer

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.