码迷,mamicode.com
首页 > 其他好文 > 详细

Latex插入图片

时间:2020-03-25 01:51:18      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:orm   figure   bmp   graph   png   htm   with   支持   环境   

latex写文章插入图片一般需要用到graphicx宏包, latex编译方式支持eps格式的图片插入,如果要插入jpgpng格式的图片,可以将图片转为eps格式或者使用pdflatex对源码进行编译。

部分论文模板默认使用的是latex编译,改为pdflatex的方式编译需要对模板改动较多且难度较大。此时若想插入jpgpng格式的图片jpgpng格式的图片有两种方式:一、将图片转为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}

转载请注明出处https://www.cnblogs.com/crazysquirrel/p/12563369.html

Latex插入图片

标签:orm   figure   bmp   graph   png   htm   with   支持   环境   

原文地址:https://www.cnblogs.com/crazysquirrel/p/12563369.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!