latex
写文章插入图片一般需要用到graphicx
宏包, latex
编译方式支持eps
格式的图片插入,如果要插入jpg
、png
格式的图片,可以将图片转为eps
格式或者使用pdflatex
对源码进行编译。
部分论文模板默认使用的是latex
编译,改为pdflatex
的方式编译需要对模板改动较多且难度较大。此时若想插入jpg
、png
格式的图片jpg
、png
格式的图片有两种方式:一、将图片转为eps
格式;二、制作图片的bb
类型文件。
将图片转为eps
格式
- 方法一
在windows系统中可以使用ctex安装时自带的bmpes工具讲png或者jpg格式的图片转为eps,使用当时如下
```
bmeps -c src.jpg dst.eps
```
该方法可将彩色图像src.jpg转为eps格式的文件dst.eps。
- 方法二
使用python的PIL库讲图片转为eps格式的图片,具体代码如下
```
from PIL import Image
img = Image.open('图片.jpg', 'r')
img.save("转换后的图片.eps","EPS")
```
eps图片在latex中的调用方式如下:
- 多张图片并排
\begin{figure}[htbp]
\centering
\includegraphics[0.45\linewidth]{figure_1.eps}
\caption{图像一说明}
\end{figure}
- 多张图片并排
\begin{figure}[htbp]
\centering
\begin{minipage}[t]{0.45\linewidth}
\centering
\includegraphics[width=2.2in]{figure_1.eps}
\caption{图像一说明}
\end{minipage}%
\begin{minipage}[t]{0.45\linewidth}
\centering
\includegraphics[width=2.2in]{figure_2.eps}
\caption{图像二说明}
\end{minipage}%
\end{figure}
经过上述两种方式的转换,会存在部分图片转换后的eps文件无法在latex中被正常显示。
制作图片的bb
类型文件
如果要继续使用latex对原始模板进行编译,则需要为每一个非eps格式的图像制作bb类型的文件。windows中为图片制作bb文件需要使用到ebb
命令,单张图片的处理命令为:
ebb figure.jpg或者ebb figure.png
如果需要处理的图片较多,可使用下属python脚本:
import os
dir_path = r'C:\Users\Administrator\Documents\latex\paper\figures' # 图片所在文件夹
os.chdir(dir_path)
for e in os.listdir('./'):
if e.endswith('png') or e.endswith('jpeg'):
os.system('ebb {0}'.format(e))
有了对应图片的bb文件,jpg和png就可以在latex编译环境下被调用。
eps图片在latex中的调用方式如下:
- 多张图片并排
\begin{figure}[htbp]
\centering
\includegraphics[0.45\linewidth]{figure_1.jpg}
\caption{图像一说明}
\end{figure}
- 多张图片并排
\begin{figure}[htbp]
\centering
\begin{minipage}[t]{0.45\linewidth}
\centering
\includegraphics[width=2.2in]{figure_1.jpg}
\caption{图像一说明}
\end{minipage}%
\begin{minipage}[t]{0.45\linewidth}
\centering
\includegraphics[width=2.2in]{figure_2.png}
\caption{图像二说明}
\end{minipage}%
\end{figure}
插入pdf格式图片报错no BoundingBox
用记事本打开图片的pdf文件,找到类似 /MediaBox [ 0 0 432 432 ]
的字段,复制中括号内的四个数字。图片插入方式改为
\begin{figure}[!htbp]
\centering
\includegraphics[bb=0 0 432 432,width=0.6\textwidth]{char_3.7_2.pdf}
\label{fg:16}
\end{figure}
转载请注明出处https://www.cnblogs.com/crazysquirrel/p/12563369.html