无法确定图形的大小

我试图在我的Latex文件中包含图形,我在OS X上用latex+dvipdf编译了这个文件。然而,Latex返回这个错误:"无法确定图形的大小&quot。

我的图形是从PowerPoint中导出的,所以我尝试了.pdf和.png。我在这两种情况下都得到了同样的错误。

不起作用的代码样本。

\begin{figure}[htb]
\begin{center}
\leavevmode
\includegraphics[width=0.8\textwidth]{graph.png}
\end{center}
\end{figure}

如果我必须手动设置图片的一些尺寸,请告诉我如何才能找到这些尺寸。我需要图像占到文本宽度的80%左右,并且居中。谢谢。

解决办法

生产DVI的latex不支持读取PNG、JPG或PDF图像的大小。你需要使用pdflatex'来实现。实际上latex在现代发行的DVI模式下是pdflatex,但由于某些原因,它只能在PDF模式下读取尺寸。然而,你可以用natwidthnatheight来说明图像的自然尺寸,这将使latex在编译时不会出错。产生的DVI文件将只链接到PDF,DVI-PDF转换器需要将其包含在最终的PDF中。AFAIKdvpdf不支持这个,但dvipdfm`支持。

\documentclass{article}

\usepackage{graphicx}

\begin{document}
\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth,natwidth=610,natheight=642]{tiger.pdf}
\end{figure}
\end{document}

用以下两种方法编译

pdflatex 

latex 
dvipdfm 
评论(7)

一种非乳胶的解决方案

一个非常快速的解决方案是将png文件转换成eps格式。这可以用图形软件轻松完成,例如Inkscape

所以,你只需要在Inkscape中打开文件,然后SaveAs并选择eps格式。

现在把tex文件的扩展名从

\includegraphics[width=0.8\textwidth]{tiger.png}

改为

\includegraphics[width=0.8\textwidth]{tiger.eps}
评论(5)

我在一个 "jpeg "文件上看到这个问题。通过把它的扩展名从.JPG改为.jpg(是的,只是把大写改为小写),错误消失了。

$ pdflatex --version
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) restricted \write18 enabled.
评论(0)