latex并排插入两幅图像

本文介绍如何在LaTeX文档中实现图片并排显示,并提供了多种配置方案,包括共享标题、独立子标题等,适用于学术论文及报告中的图表布局。

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

下面是一些latex中并排两图的代码,以备今后使用

from:  http://blog.csdn.net/qq_22812319/article/details/51958958


\documentclass{article}
\usepackage{graphicx} %use graph format
\usepackage{subfig}

%%
%%Figures
%%
\begin{figure}
  \centering
  \subfigure[house]{
    %\label{fig:subfig:a} %% label for first subfigure
    \includegraphics[width=1.5in]{./a.png}
  }
  \subfigure[hotel]{
    %\label{fig:subfig:b} %% label for second subfigure
    \includegraphics[width=1.5in]{./b.png}
  }
  \caption{Frames of the house and hotel data sets}
  %\label{fig:subfig} %% label for entire figure
\end{figure}


%上述代码结果如下


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%下面是从网上找的代码                                                                                                                                        %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{figure}[!htp]
    \begin{minipage}[t]{0.5\linewidth}%设定图片下字的宽度,在此基础尽量满足图片的长宽
    \centering
    \includegraphics[height=2.4cm,width=3.8cm]{figure1a.JPG}
    \caption*{(a) This is the left picure.}%加*可以去掉默认前缀,作为图片单独的说明
    \label{fig:side:a}
    \end{minipage}
    \begin{minipage}[t]{0.5\linewidth}%需要几张添加即可,注意设定合适的linewidth
    \centering
    \includegraphics[height=2.4cm,width=3.8cm]{figure1b.JPG}
    \caption*{(b)This is the right picture.}
    \label{fig:side:b}
    \end{minipage}
    \caption{This is total name.}%n张图片共享的说明
\end{figure}
\end{document}



from:http://zhaoshiliang.wordpress.com/2010/07/27/%E5%A4%9A%E5%9B%BE%E6%8E%92%E7%89%88/

1. 并排摆放,共享标题
当我们需要两幅图片并排摆放,并共享标题时,可以在 figure 环境中
使用两个 \includegraphics 命令。

\begin{figure}[htbp]
\centering
\includegraphics{left}
\includegraphics{right}
\caption{反清复明}
\end{figure}

2. 并排摆放,各有标题
如果想要两幅并排的图片各有自己的标题,可以在 figure 环境中使用
两个 minipage 环境,每个环境里插入一个图。
\begin{figure}[htbp]
\centering
\begin{minipage}[t]{0.3\textwidth}
\centering
\includegraphics{left}
\caption{清明}
\end{minipage}

\begin{minipage}[t]{0.3\textwidth}
\centering
\includegraphics{right}
\caption{反复}
\end{minipage}
\end{figure}

3.并排摆放,共享标题,各有子标题
如果想要两幅并排的图片共享一个标题,并各有自己的子标题,可以使用 subfig 宏包提供的 \subfloat 命令。
subfloat 命令缺少宽度参数。虽然我们可以用 \hspace 命令调整子图的距离,子标题却只能和子图本身一样宽,就会出现折行。
为了避免子标题折行,我们可以在 \subfloat 里再嵌套个 minipage,因为后者是有宽度的。
\begin{figure}[htbp]
\centering
\subfloat[清明]{
\label{fig:improved_subfig_a}
\begin{minipage}[t]{0.3\textwidth}
\centering
\includegraphics{left}
\end{minipage}
}
\subfloat[反复]{
\label{fig:improved_subfig_b}
\begin{minipage}[t]{0.3\textwidth}
\centering
\includegraphics{right}
\end{minipage}
}
\caption{反清复明}
\end{figure}





### 实现LaTeX并排插入两张片 在LaTeX中实现两张并排显示可以通过多种方法完成,其中最常用的是利用`minipage`环境或`subcaption`宏包。以下是两种常见的解决方案: #### 方法一:使用 `minipage` 环境 通过定义两个独立的 `minipage` 来放置每张片,并设置它们的宽度比例以便在同一行显示。 ```latex \documentclass{article} \usepackage[demo]{graphicx} \begin{document} \begin{figure}[htbp] \centering % 定义第一个 minipage \begin{minipage}{0.45\textwidth} \centering \includegraphics[width=\linewidth]{image1.png} % 替换为实际片路径 \caption{第一张片说明} \label{fig:image1} \end{minipage}\hfill % 定义第二个 minipage \begin{minipage}{0.45\textwidth} \centering \includegraphics[width=\linewidth]{image2.png} % 替换为实际片路径 \caption{第二张片说明} \label{fig:image2} \end{minipage} \end{figure} \end{document} ``` 上述代码中的 `\hfill` 命令用于填充两个 `minipage` 之间的空白区域[^1]。如果希望减少间距,可以移除该命令或将它替换为空格或其他调整工具。 --- #### 方法二:使用 `subcaption` 宏包 对于更复杂的场景(如需要共享父标题),推荐使用 `subcaption` 宏包。它可以轻松创建带有子标题的并排片布局。 首先,在导言区加载必要的宏包: ```latex \usepackage{graphicx} \usepackage{subcaption} ``` 接着编写如下代码: ```latex \documentclass{article} \usepackage[demo]{graphicx} \usepackage{subcaption} \begin{document} % 创建一个 figure 环境作为整体容器 \begin{figure}[htbp] \centering % 插入第一张子 \begin{subfigure}[b]{0.45\textwidth} \centering \includegraphics[width=\linewidth]{image1.png} % 替换为实际片路径 \caption{第一张子描述} \label{fig:sub-image1} \end{subfigure} % 添加适当间隔 \hfill % 插入第二张子 \begin{subfigure}[b]{0.45\textwidth} \centering \includegraphics[width=\linewidth]{image2.png} % 替换为实际片路径 \caption{第二张子描述} \label{fig:sub-image2} \end{subfigure} % 整体大标题 \caption{这是整个形的大标题} \label{fig:main-figure} \end{figure} \end{document} ``` 此方法允许每张子有自己的小标题,同时还可以给整组图像提供一个共同的大标题[^2]。 --- ### 注意事项 为了提高文档可读性和维护效率,请遵循以下建议: - 片文件名应具有意义,避免仅用数字命名(例如 `img_thermal_analysis`, 而不是 `1.jpg` 或者中文名称)[^3]。 - 如果需要跨多个页面管理大量片,则考虑优化存储结构以及合理分配标签和引用关系[^4]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值