EPS 转换为 PDF:缺少插入的 $

EPS 转换为 PDF:缺少插入的 $

我正在编译一个非常简单的文档,嵌入一个 EPS 图像。Latex 将此图像转换为 PDF,文件显示在目录中 - 到目前为止一切顺利。但是,我收到错误“缺少 $ 插入”,并且图像未显示在文档中(尽管文档确实被编译)。可能是什么问题?

\documentclass{article}
\usepackage{graphicx}
\newcommand*\myphone{\vcenter{\hbox{\includegraphics{smartphone.eps}}}}

\begin{document}

Hello World! \myphone

\end{document}

以及日志文件中的相关部分:

Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4

38.

Package grfext Info: Graphics extension search list:
(grfext) [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 456.
)

! Missing $ inserted.

<inserted text> 

   $

l.8 Hello World! \myphone

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

LaTeX Font Info: External font `cmex10' loaded for size
(Font)           <7> on input line 8.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 8.
Package epstopdf Info: Source file: <smartphone.eps>
(epstopdf)                    date: 2018-08-15 09:42:54
(epstopdf)                    size: 5318 bytes
(epstopdf)             Output file: <smartphone-eps-converted-to.pdf>
(epstopdf)                    date: 2018-08-15 09:51:21
(epstopdf)                    size: 3698 bytes
(epstopdf)             Command: <epstopdf --outfile=smartphone-eps-converted-to
.pdf smartphone.eps>
(epstopdf)             \includegraphics on input line 8.
Package epstopdf Info: Output file is already uptodate.
<smartphone-eps-converted-to.pdf, id=1, 175.65625pt x 315.1775pt>
File: smartphone-eps-converted-to.pdf Graphic file (type pdf)
<use smartphone-eps-converted-to.pdf>
Package pdftex.def Info: smartphone-eps-converted-to.pdf  used on input line 8.

(pdftex.def)             Requested size: 175.6558pt x 315.17673pt.
! Missing $ inserted.
<inserted text> 
                $
l.9 

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

答案1

\vcenter是需要数学模式的(原始)命令。通常不应在用户级别使用它。最好使用 \raisebox 来移动图形:

\documentclass{article}
\usepackage{graphicx}
\newcommand*\myphone{\raisebox{-0.5\height}{\includegraphics[width=5mm]{example-image-duck}}}

\begin{document}

Hello World! \myphone

\end{document}

在此处输入图片描述

答案2

您可以用来adjustbox微调垂直对齐。

正确的命令取决于您的 EPS/PDF 图像。

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\DeclareRobustCommand{\myphone}{\includegraphics{smartphone}}
\DeclareRobustCommand{\myphonec}{\includegraphics[valign=c]{smartphone}}
\DeclareRobustCommand{\myphoneC}{\includegraphics[valign=C]{smartphone}}

\begin{document}

Hello World! \myphone\ Hello World!

Hello World! \myphonec\ Hello World!

Hello World! \myphoneC\ Hello World!

\end{document}

在此处输入图片描述

相关内容