latex一个图中插入多个子图

本文记录了如何在 LaTeX 中成功插入多个子图,通过引用 overleaf 官方示例并修改代码,实现了在同一个图形环境中放置两个子图。关键在于使用 usepackage{subcaption} 包,并调整子图宽度如 0.5 extwidth 或 0.9linewidth,以及正确引用图片名称。若要使子图居中,可以添加 centering 指令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网上找了好多文章代码,总是出错,找overleaf官网文件,找到了示例代码改了一下,成功应用,记录一下:
官网指导说明:
https://www.overleaf.com/learn/latex/Positioning_images_and_tables#Multiple_images_in_one_figure

源代码如下:(一个图两个子图)

\begin{figure}[h]

\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=6cm]{overleaf-logo} 
\caption{Caption1}
\label{fig:subim1}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=6cm]{mesh}
\caption{Caption 2}
\label{fig:subim2}
\end{subfigure}

\caption{Caption for this figure with two images}
\label{fig:image2}
\end{figure}

注意:0.5\textwidth,识别\textwidth为尺度单位(cm,mm之类的),需要在引言部分导入包:(在: \begin{document} 命令之前导入)
\usepackage{subcaption}

0.9\linewidth:可以改成想要的单位,如:5.4cm

{overleaf-logo},{mesh}:注意这里是图片名称,导入的图片可能是带后缀的,如:图3.npg,这里不能是{图3.npg},必须用{图3}

另外如果想要子图片居中,插入:\centering
如:

\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[width=0.9\linewidth, height=6cm]{overleaf-logo} 
\caption{Caption1}
\label{fig:subim1}
\end{subfigure}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值