我有一个简单的问题,但我不知道该怎么做。我想在同一页上放置 10 个图形:5 行 2 列的网格。
我应该输入什么才能像这样插入图形并具有相同的对齐/大小?最终带有自定义标题... ;)
答案1
这里有几种可能性。
案例 A:十个子图
有三个选项:第一个,使用subfig
包;第二个,使用subcaption
包;第三个,使用floatrow
包裹。
使用子图:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\captionsetup[subfigure]{justification=raggedright}
\begin{document}
\begin{figure}
\centering
\subfloat[first subfigure]{\label{sfig:a}\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subfloat[second subfigure]{\label{sfig:b}\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subfloat[third subfigure]{\label{sfig:c}\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subfloat[fourth subfigure]{\label{sfig:d}\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subfloat[fifth subfigure]{\label{sfig:e}\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\\
\subfloat[sixth subfigure]{\label{sfig:f}\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subfloat[seventh subfigure]{\label{sfig:g}\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subfloat[eighth subfigure]{\label{sfig:h}\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subfloat[ninth subfigure]{\label{sfig:i}\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subfloat[tenth subfigure]{\label{sfig:j}\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\\
\caption{A figure with ten subfigures}
\label{fig:test}
\end{figure}
\end{document}
使用子标题:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup[subfigure]{justification=raggedright}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{first subfigure\label{sfig:a}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subcaptionbox{second subfigure\label{sfig:b}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subcaptionbox{third subfigure\label{sfig:c}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subcaptionbox{fourth subfigure\label{sfig:d}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\hfill
\subcaptionbox{fifth subfigure\label{sfig:e}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}\\
\subcaptionbox{sixth subfigure\label{sfig:f}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subcaptionbox{seventh subfigure\label{sfig:g}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subcaptionbox{eighth subfigure\label{sfig:h}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subcaptionbox{ninth subfigure\label{sfig:i}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\hfill
\subcaptionbox{tenth subfigure\label{sfig:j}}{\includegraphics[width=.18\textwidth,height=2cm]{example-image-b}}\\
\caption{A figure with ten subfigures}
\label{fig:test}
\end{figure}
\end{document}
使用 floatrow:
\documentclass{article}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{graphicx}
\renewcommand\subfloatrowsep{\hskip7pt}
\begin{document}
\begin{figure}
\captionsetup{justification=raggedright}
\ffigbox[\textwidth]{%
\begin{subfloatrow}[5]
\ffigbox[\FBwidth]{\caption{first subfigure}\label{sfig:a}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{second subfigure}\label{sfig:b}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{third subfigure}\label{sfig:c}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{fourth subfigure}\label{sfig:d}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{fifth subfigure}\label{sfig:e}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\end{subfloatrow}
\begin{subfloatrow}[5]
\ffigbox[\FBwidth]{\caption{sixth subfigure}\label{sfig:f}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{seventh subfigure}\label{sfig:g}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{eighth subfigure}\label{sfig:h}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{ninth subfigure}\label{sfig:i}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\ffigbox[\FBwidth]{\caption{tenth subfigure}\label{sfig:j}}
{\includegraphics[width=.18\textwidth,height=2cm]{example-image-a}}
\end{subfloatrow}
}{\caption{A figure with ten subfigures}\label{fig:test}}
\end{figure}
\end{document}
案例 B:十个独立人物
如果我们谈论的是十个独立数字的数组,则minipage
可以使用十。
如果允许整个构造浮动,则minipage
s 可以进入图形环境:
\documentclass{article}
\usepackage{caption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\captionsetup{justification=raggedright}
\centering
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{first figure}
\label{fig:a}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{second figure}
\label{fig:b}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{third figure}
\label{fig:c}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{fourth figure}
\label{fig:d}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{fifth figure}
\label{fig:e}
\end{minipage}\\
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{sixth figure}
\label{fig:f}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{seventh figure}
\label{fig:g}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{eighth figure}
\label{fig:h}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{ninth figure}
\label{fig:i}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\caption{tenth figure}
\label{fig:j}
\end{minipage}
\end{figure}
\end{document}
如果整个构造不允许浮动,则十minipage
位可以放入一个minipage
环境(或一个环境)内;在这种情况下,可以使用(来自或包)center
提供标题:\captionof
caption
capt-of
\documentclass{article}
\usepackage{caption}
\usepackage{graphicx}
\begin{document}
\noindent\begin{minipage}{\textwidth}
\captionsetup{justification=raggedright}
\centering
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{first figure}
\label{fig:a}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{second figure}
\label{fig:b}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{third figure}
\label{fig:c}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{fourth figure}
\label{fig:d}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{fifth figure}
\label{fig:e}
\end{minipage}\\
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{sixth figure}
\label{fig:f}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{seventh figure}
\label{fig:g}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{eighth figure}
\label{fig:h}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{ninth figure}
\label{fig:i}
\end{minipage}\hfill
\begin{minipage}[t]{.18\textwidth}
\includegraphics[width=\linewidth,height=2cm]{example-image-a}
\captionof{figure}{tenth figure}
\label{fig:j}
\end{minipage}
\end{minipage}
\end{document}
答案2
如果您不需要(例如,hyperref)链接到每个单独的子图,那么这可能会起作用,尽管它相当紧凑。我还假设您的图形是统一大小,因为您说将它们放在一个规则的数组中。如果我错了,请纠正我。
\documentclass{article}
\usepackage{stackengine}
\begin{document}
\def\myfig{\rule{.8in}{1in}}
\newcommand\mycap[2]{\parbox[t]{.8in}{\raggedright(#1) #2}}
\begin{figure}
\small\centering
\Shortstack{%
{\protect\myfig} {\protect\mycap{a}{Caption for subfig a}} {}
{\protect\myfig} {\protect\mycap{f}{Caption for subfig f}}
}
\Shortstack{%
{\protect\myfig} {\protect\mycap{b}{Caption for subfig b}} {}
{\protect\myfig} {\protect\mycap{g}{Caption for subfig g}}
}
\Shortstack{%
{\protect\myfig} {\protect\mycap{c}{Caption for subfig c}} {}
{\protect\myfig} {\protect\mycap{h}{Caption for subfig h}}
}
\Shortstack{%
{\protect\myfig} {\protect\mycap{d}{Caption for subfig d}} {}
{\protect\myfig} {\protect\mycap{i}{Caption for subfig i}}
}
\Shortstack{%
{\protect\myfig} {\protect\mycap{e}{Caption for subfig e}} {}
{\protect\myfig} {\protect\mycap{j}{Caption for subfig j}}
}
\caption{Overall Figure Caption}
\end{figure}
\end{document}