如何在 LaTex 中将多幅图像放在一行中?

如何在 LaTex 中将多幅图像放在一行中?

我想知道如何在 Latex 中将 3 幅图像放在一行中,使其看起来像以下格式: 在此处输入图片描述

谁能帮帮我!非常感谢!

注意:图形需要跨越multicols环境内的两列。

答案1

以下是如何在列中定位数字multicol

\documentclass{article}

\usepackage{multicol}
\usepackage{lipsum}
\usepackage{mwe}

\begin{document}
    \begin{multicols}{2}
        \begin{figure*}[ht!]
            \includegraphics[width=.3\textwidth]{example-image-a}\hfill
            \includegraphics[width=.3\textwidth]{example-image-b}\hfill
            \includegraphics[width=.3\textwidth]{example-image-c}
            \caption{Image A.}
            \caption{Image B.}
            \caption{Image C.}
        \end{figure*}
        \lipsum[1-10]
    \end{multicols}
\end{document}

请注意,我使用的是带星号的环境版本figure[ht]标签指定位置,这里表示“在此页面顶部”。请 Google 搜索“LaTeX Floats”以了解如何更改它以及如何调整环境figure

这里:仅复制\粘贴此部分:

        \begin{figure*}[ht!]
            \includegraphics[width=.3\textwidth]{example-image-a}\hfill
            \includegraphics[width=.3\textwidth]{example-image-b}\hfill
            \includegraphics[width=.3\textwidth]{example-image-c}
            \caption{Image A.}
            \caption{Image B.}
            \caption{Image C.}
        \end{figure*}

答案2

我刚刚准备了一个问题/答案(见这里) 并且我认为代码适合这里的问题。我提供了基于subcaption包的不同示例。

\documentclass{article}

\usepackage[
    showframe, % This option shows the margins and so on -- remove it in the final version
]{geometry}

\usepackage{graphicx}

% Here: H option for float placement
\usepackage{float}

% caption and subcaption work together
\usepackage{subcaption} % loads the caption package

\begin{document}

\section{Two Figures}
\subsection{Horizontal}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.45\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}{\includegraphics[width=0.45\textwidth]{example-image-b}}%
\caption{Caption}
\end{figure}

\subsection{Vertical}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.45\textwidth]{example-image-a}}%
\\ % <-- Line break
\subcaptionbox{Subcaption B}{\includegraphics[width=0.45\textwidth]{example-image-b}}%
\caption{Caption}
\end{figure}

\section{Three Figures}
\subsection{Horizontal}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.30\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}{\includegraphics[width=0.30\textwidth]{example-image-b}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption C}{\includegraphics[width=0.30\textwidth]{example-image-C}}%
\caption{Caption}
\end{figure}

\subsection{Vertical}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.30\textwidth]{example-image-a}}%
\\ % <-- Line break
\subcaptionbox{Subcaption B}{\includegraphics[width=0.30\textwidth]{example-image-b}}%
\\ % <-- Line break
\subcaptionbox{Subcaption C}{\includegraphics[width=0.30\textwidth]{example-image-C}}%
\caption{Caption}
\end{figure}

\subsection{Mixed}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.30\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}{\includegraphics[width=0.30\textwidth]{example-image-b}}%
\\ % <-- Line break
\subcaptionbox{Subcaption C}{\includegraphics[width=0.30\textwidth]{example-image-C}}%
\caption{Caption}
\end{figure}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.45\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}{\includegraphics[width=0.45\textwidth]{example-image-b}}%
\\ % <-- Line break
\subcaptionbox{Subcaption C}{\includegraphics[width=0.30\textwidth]{example-image-C}}%
\caption{Caption}
\end{figure}

\section{Four Figures}
\subsection{Horizontal}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.20\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}{\includegraphics[width=0.20\textwidth]{example-image-b}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption C}{\includegraphics[width=0.20\textwidth]{example-image-C}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption D}{\includegraphics[width=0.20\textwidth]{example-image}}%
\caption{Caption}
\end{figure}

\subsection{Mixed}

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.45\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}{\includegraphics[width=0.45\textwidth]{example-image-b}}%
\\ % <-- Line break
\subcaptionbox{Subcaption C}{\includegraphics[width=0.45\textwidth]{example-image-C}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption D}{\includegraphics[width=0.45\textwidth]{example-image}}%
\caption{Caption}
\end{figure}

\section{Symmetric Padding}

See the following example with small picture widths.

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}{\includegraphics[width=0.20\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}{\includegraphics[width=0.20\textwidth]{example-image-b}}%
\\ % <-- Line break
\subcaptionbox{Subcaption C}{\includegraphics[width=0.20\textwidth]{example-image-C}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption D}{\includegraphics[width=0.20\textwidth]{example-image}}%
\caption{Caption}
\end{figure}

You can use the optional argument of the \texttt{\textbackslash subcaptionbox} in order to define the width of the sub element.

\begin{figure}[H]
\centering
\subcaptionbox{Subcaption A}[0.50\textwidth]{\includegraphics[width=0.20\textwidth]{example-image-a}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption B}[0.50\textwidth]{\includegraphics[width=0.20\textwidth]{example-image-b}}%
\\ % <-- Line break
\subcaptionbox{Subcaption C}[0.50\textwidth]{\includegraphics[width=0.20\textwidth]{example-image-C}}%
\hfill % <-- Seperation
\subcaptionbox{Subcaption D}[0.50\textwidth]{\includegraphics[width=0.20\textwidth]{example-image}}%
\caption{Caption}
\end{figure}

Here I try to illustrate the idea behind the solution -- \textbf{don't use this code}!

\begin{figure}[H]
\centering
\fbox{%
\subcaptionbox{Subcaption A}[0.482\textwidth]{\includegraphics[width=0.20\textwidth]{example-image-a}}%
}%
\hfill % <-- Seperation
\fbox{%
\subcaptionbox{Subcaption B}[0.482\textwidth]{\includegraphics[width=0.20\textwidth]{example-image-b}}%
}%
\\ % <-- Line break
\fbox{%
\subcaptionbox{Subcaption C}[0.482\textwidth]{\includegraphics[width=0.20\textwidth]{example-image-c}}%
}%
\hfill % <-- Seperation
\fbox{%
\subcaptionbox{Subcaption D}[0.482\textwidth]{\includegraphics[width=0.20\textwidth]{example-image}}%
}%
\caption{Caption}
\end{figure}

\end{document}

在此处输入图片描述

答案3

这里有一个方法可以做你想做的事,也许它不是最好的,但它可以完成工作,使用 multicol 包,只需使用 \columsep 和图像的比例,对于图形名称使用 caption 包作为下面的代码

\documentclass{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2.5cm]{geometry}

\begin{document}
\begin{multicols}{3}[\columnsep=3cm]
\includegraphics[scale=0.3]{Figura}
\columnbreak
\includegraphics[scale=0.3]{Figura}
\columnbreak
\includegraphics[scale=0.3]{Figura}
\end{multicols}
\captionof{figure}{Name of the figure}
\end{document}

在此处输入图片描述

这是结果,不要太关注猫,这是我能找到的第一张图片,希望它能有所帮助

答案4

要在 LaTeX 中执行此操作,我认为您需要查看该subfig软件包。文档清晰且写得很好,似乎提供了您想要的功能。结合 Ryan 关于 中跨列数字的回答multicol,您应该可以得到您想要的东西。(Ryan 的答案本身也能让您得到想要的东西;但有一个软件包可以做到这一点,通常都是这样的。)

但 TeX 的工作原理很简单,就是以各种方式将框推到一起,有时框之间会留出一定量的空间;这个空间可以是固定的(“跳过”),也可以是可变的(“粘合”,可以根据排版需要拉伸或收缩)。这些框有两种形式: \hboxes,水平方向;和\vboxes,垂直方向。它们可以无限嵌套(实际上不是,因为 TeX 的内存有限,但没有概念上的限制)。

例如,考虑一个段落。每个字母都是一个框;单词和行之间的空间是胶合(它们在一定范围内伸展或收缩);TeX 根据其复杂的惩罚系统将它们放在水平框(每行)和垂直框(排列成段落的行)中,从而获得最佳结果。

这是通过段落排版自动完成的;但也可以通过明确设置框来手动完成。摆弄框非常有趣,让我们看看在这种情况下如何做到这一点:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\hbox to\linewidth{%
    \hfil%
    \includegraphics[scale=0.2]{Bo0MI.jpg}%
    \hfil%
    \includegraphics[scale=0.2]{Bo0MI.jpg}%
    \hfil%
    \includegraphics[scale=0.2]{Bo0MI.jpg}%
    \hfil%
}
\end{document}

至于在每张图片下添加标题,它看起来已经是一个标题了图像的一部分;但如果您想要除现有内容之外的内容,您可以通过多种方式实现。例如,直接使用方框摆弄:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\hbox to\linewidth{%
    \hfil%
    \vbox{%
        \hbox{\includegraphics[scale=0.15]{Bo0MI.jpg}}%
        \hbox{Some caption here.}
    }%
    \hfil%
    \vbox{%
        \hbox{\includegraphics[scale=0.15]{Bo0MI.jpg}}%
        \hbox{Another caption here.}
    }%
    \hfil%
    \vbox{%
        \hbox{\includegraphics[scale=0.15]{Bo0MI.jpg}}%
        \hbox{A third caption here.}
    }%
    \hfil%
}
\end{document}

带有标题的间隔图像。

当然,如果这不是一次性的事情,您可能希望为其定义一个新命令;但是既然subfig已经这样做了,您可以跳过开销。没有必要重新发明轮子。

盒子远不止这些,但这就是事物背后的概念。任何好的 TeX 参考资料都可以告诉你更多。

相关内容