Latex插入圖片


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}

插入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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM