![图像方向](https://linux22.com/image/289108/%E5%9B%BE%E5%83%8F%E6%96%B9%E5%90%91.png)
当我将多张图片导入 LaTeX 时,默认图片会直接显示在前一张图片的下方。如何才能在同一行并排显示这些图片(即使多达五张图片)?
另外,我怎样才能让三行图像一个接一个地显示出来?
答案1
我认为这是一个误解;默认\includegraphics
是不是将一张图片放置在另一张图片下方,就是将它们放置在您告诉 LaTeX 放置它们的位置;\includegraphics
将图像放置在指定的位置。
请看以下示例,其中显示了两种情况:第一种情况,两幅图像嵌套放置,中间没有空格(如您所见,即使图像的总宽度超出了文本区域的宽度,图像也会相邻放置);第二种情况,由于命令之间留有空行,因此图像将一个接一个地显示\includegraphics
(空行相当于\par
,因此第二幅图像开始它自己的段落):
\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}% to show the page layout
\begin{document}
Two images one after the other even if they protrude into the right margin
{\centering
\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}%
\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}\par
}
\vspace*{1cm}
Two images, one below the other since a blank line (i.e., a \verb+\par+ command) was left in between:
{\centering
\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}
\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}\par
}
\end{document}
根据你的设置后,图像可以按任意所需排列。当然,对于图像行,理想的做法是采取预防措施(例如,通过控制图像的宽度)以使总宽度不超过文本区域的宽度(但即使需要,也可以使用 等超出该尺寸\makebox
)。
举个小例子:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\noindent\begin{minipage}{\textwidth}
\centering
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}
\end{minipage}
\vspace{1cm}
\noindent\begin{minipage}{\textwidth}
\centering
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}
\end{minipage}
\vspace{1cm}
\noindent\begin{minipage}{\textwidth}
\centering
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}
\end{minipage}
\end{document}
在上面的例子中,我使用了(实际上不是需要的)静态环境(minipage
)来放置图像组,但同样的也适用于浮动figure
环境(见下面的例子)。
如果您有兴趣将图像视为子图像,某些软件包可以为您提供其他有用的功能,例如为图像添加标题:
\subcaptionbox
使用包中的一个小例子subcaption
来生成一个 3x3 的子图数组,每个子图都有自己的标题,以及整个图形的通用标题:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{sub 1\label{fig:testa}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 2\label{fig:testb}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 3\label{fig:testc}}{\includegraphics[width=.15\textwidth]{example-image-a}}\par\medskip
\subcaptionbox{sub 4\label{fig:testd}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 5\label{fig:teste}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 6\label{fig:testf}}{\includegraphics[width=.15\textwidth]{example-image-a}}\par\medskip
\subcaptionbox{sub 7\label{fig:testg}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 8\label{fig:testh}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 9\label{fig:testi}}{\includegraphics[width=.15\textwidth]{example-image-a}}
\caption{a figure with nine subfigures in a $3\times 3$ array}
\label{fig:test}
\end{figure}
\end{document}