0

I am trying to set the max width of an image by using the adjustbox package. What I want is that an image only scales DOWN to \linewidth if needed. But if it smaller than \linewidth then it should NOT be scaled at all. However when using the following code, the image gets still scaled to \linewidth

\documentclass[a4paper]{scrreprt}


\usepackage[pdftex]{graphicx}


\usepackage[export]{adjustbox} 


\begin{document}
xxxxx
\begin{figure}[H]
    \centering
    \adjincludegraphics[max width=\linewidth]{images/dialog.png}
    \caption[asdf]{asdf}
    \label{fig:dialog}
\end{figure}
yyyyyyyyyy
\end{document}

enter image description here

What did I miss?

  • 1
    looks good to me. Where did you get the actual size from? Please recheck the size of your png. Maybe it is bigger, than you think it is. – LaRiFaRi Jul 4 '14 at 8:59
  • The actual size is from a screenshot of the program displaying the dialog. That screenshot is then also used in the latex document as a figure. The figure is clearly bigger than the actual size (?) – IHeartAndroid Jul 4 '14 at 9:37
  • Sorry, can't help you there. A last check: include it with scale=1 or no option at all. In this case it should have the actual size (or you will see, which size LaTeX thinks, it has...) – LaRiFaRi Jul 4 '14 at 9:39
  • If the included image is larger in the PDF than as original on screen then this might be an issue with the image density: Dots per inch (DPI) etc. As your code looks correct I guess you should check the image metadata and compare the size without scaling as @LaRiFaRi suggested above. – Martin Scharrer Jan 5 at 18:51
1

Some information is missing from your question. Since, I do not have that specific image to test with, I must raise a few queries.

  1. Did you crop out the required dialogue box from your screenshot and then used the cropped image in LaTeX?
  2. If so, post-cropping did you resize the image? If not, as @LaRiFaRi mentions, what is its original resolution? For example, width=221 pixels at 96 dpi & height=334 pixels at 96 dpi

This way, looking at the original resolution of just the required part within your screenshot (e.g. the dialogue box) should give you an idea.

  1. Also, do you intend to use \linewidth or \textwidth? Both are quite different! In your current situation, the difference may not matter. However, from the conventional point of view:

A \linewidth is defined as -- The width of a line in the local environment.
A \textwidth is defined as -- The width of the text on the page. (fixed design-oriented length) ; for reference, see: LaTeX default lengths

Also see this scintillating discussion on Difference between \textwidth, \linewidth and \hsize, which includes a nicely illustrated example that shows the difference between these lengths in different situations.

  1. To print the exact size of either of these lengths, use the following after \begin{document} :

    textwidth = \the\textwidth ; linewidth = \the\linewidth ; hsize = \the\hsize

    In onecolumn mode, all three lengths should be equal.

  2. Now, you can compare your original image resolution and the size of your selected width parameter to determine if the image is smaller or larger than the width. For unit conversions, see: Units used in LaTeX

That should provide you with enough tools to troubleshoot your own problem! Happy hunting!!

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.