latex一个图中插入多个子图

网上找了好多文章代码,总是出错,找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}

猜你喜欢

转载自blog.csdn.net/qq_44425179/article/details/131580692