The DVI producing latex
doesn't support reading the size of PNG, JPG or PDF images. You need to use pdflatex
for this. Actually latex
is pdflatex
in DVI mode in modern distributions, but it can read the sizes only in PDF mode for some reason. You are however able to state the natural size of the images using natwidth
and natheight
which will make latex
compile without error. The produced DVI file will only link to the PDF and the DVI-to-PDF converter will need to include it in the final PDF. AFAIK dvpdf
doesn't support this but dvipdfm
does.
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth,natwidth=610,natheight=642]{tiger.pdf}
\end{figure}
\end{document}
Compile with either
pdflatex <file base>
or
latex <file base>
dvipdfm <file base>
When you take a screenshot or export a figure from Matlab as a rasterised image,usually the resulting image file will not contain any resolution information (or "pixel density", usually measured in "dots per inch", or "DPI") in its metadata. When you include such an image in a LaTeX document using \includegraphics
, a resolution of 72 DPI will be assumed. For example, that means that a screenshot that has a size of 1440x900 px will have a width of 1440 px / 72 px per in = 20 in = 51 cm in your PDF or DVI, so it will most likely be too big for your document. A computer monitor with a horizontal width of 15 in (= 38 cm) that is operated at a screen size of 1440x900 px has a resolution of 1440 px / 15 in = 96 dpi. If you want your screenshot to have the same size (in this case a width of 38 cm) both on your computer screen and in the printed document, you need find a way of letting LaTeX know that the resolution of the image is 96 DPI. There are a number of ways you can do this:
As an option to includegraphics
:
If you're compiling your document using pdflatex
, you can specify the resolution of the image by loading it using \includegraphics [resolution=<resolution in DPI>] {<filename>}
. This will only work if no resolution information is included in the image.
By setting the image metadata using GIMP:
Go to Image
-> Scale Image...
and adjust the X and Y resolution after making sure pixels/in
is chosen in the drop down menu. Then save your image.
By setting the image metadata using IrfanView:
In IrfanView 4.30, you can click Image - Information
(or press I) to show the metadata of the image. The fifth row is called Resolution
and should contain two fields in which you can set the horizontal and vertical resolution in dots per inch. By pressing the button Change
, the new resolution will be set. The "physical" size of the image in cm and inch, which is obtained by multiplying the size in pixels with the resolution, is shown in the eigth line, called Print Size (from DPI)
. You can then include the image in your LaTeX document by calling \includegraphics {<filename>}
without any extra options.
By setting the image metadata using ImageMagick:
On Linux systems, frequently the ImageMagick programs are already present or can easily be installed. You can then set the resolution information by calling convert <original file name> -density <resolution> -units PixelsPerInch <new file name>
in a shell. You can then include the image in your LaTeX document by calling \includegraphics {<filename>}
without any extra options.
Best Answer
I can't think of a simple solution, but here's a possible solution that adapts the internals command used by
\includegraphics
.It only works with PDFLaTeX.