我希望实现相同大小图形的网格布局,每个图形下面都有自己的标题。我最初的想法是将\figure
环境放在\tabularx
这样的
\begin{tabularx}{\linewidth}{llll}
\begin{figure}[h]
\caption{Example of a parametric plot ($\sin (x), \cos(x), x$)}
\centering
\includegraphics[width=0.5\textwidth]{link.pdf}
\end{figure}
&
\begin{figure}[h]
\caption{Example of a parametric plot ($\sin (x), \cos(x), x$)}
\centering
\includegraphics[width=0.5\textwidth]{link.pdf}
\end{figure}
\\
\begin{figure}[h]
\caption{Example of a parametric plot ($\sin (x), \cos(x), x$)}
\centering
\includegraphics[width=0.5\textwidth]{link.pdf}
\end{figure}
&
\begin{figure}[h]
\caption{Example of a parametric plot ($\sin (x), \cos(x), x$)}
\centering
\includegraphics[width=0.5\textwidth]{link.pdf}
\end{figure}
\\
\end{tabularx}
但它失败了
! LaTeX Error: Not in outer par mode.
正确的做法是什么?所有图片都应具有相同的大小,但我不能保证标题(可能有为多行)。
答案1
将大小相同但标题文本长度不同的图像并排放置会导致标题位于图像上方的问题。 因此,我建议将标题置于图像下方。 这样,我会将每一行放入一个中figure
,这样它们仍然可以逐行浮动:
\documentclass{article}
\usepackage{mwe}
\begin{document}
\blindtext
\begin{figure}
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-a}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-b}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}
\end{figure}
\begin{figure}
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-c}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}
\end{figure}
\blindtext
\begin{figure}
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-a}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-b}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}\hfill
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-c}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}%
\end{figure}
\begin{figure}
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-a}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-b}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}\hfill
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-c}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.2\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}%
\end{figure}
\blindtext
\end{document}
由于图片上方有标题,因此很难决定其垂直位置应该如何,也许是:
\documentclass{article}
\usepackage[position=top]{caption}
\usepackage{mwe}
\begin{document}
\blindtext
\begin{figure}
\begin{minipage}[t]{.45\textwidth}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-a}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-b}
\end{minipage}
\end{figure}
\begin{figure}
\begin{minipage}[t]{.45\textwidth}
\caption{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\caption{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-a}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-b}
\end{minipage}
\end{figure}
\blindtext
\end{document}
如果您不希望数字浮动,您可以使用包float
并将选项添加[H]
到我的示例中的所有figure
环境中,或者根本不使用任何figure
环境:
\documentclass{article}
\usepackage{caption}
\usepackage{mwe}
\begin{document}
\blindtext[3]
\begin{flushleft}
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-a}
\captionof{figure}{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-b}
\captionof{figure}{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}
\bigskip
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image-c}
\captionof{figure}{Example of a short caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.75\linewidth]{example-image}
\captionof{figure}{Example of a longer caption needing more than one line and
therefore having linebreaks.}
\end{minipage}
\end{flushleft}
\blindtext
\end{document}
答案2
从评论来看,您不想浮动图像,所以这figure
是错误的构造(尽管您可以使用它[H]
来制作figure
非浮动图像)这里我只使用 parboxes,每行 3 个,但如果您适当调整宽度,则可以使用更多或更少。:
\parbox[b]{.3\textwidth}{\captionof{figure}{\raggedright#5}\includegraphics[width=\linewidth]{#6}}\par
\medskip
}
\begin{document}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\imgrow
{Example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-a}
{Another example of a parametric plot ($\sin (x), \cos(x), x$)}{example-image-b}
{Example of a parametric plot ($\sin (x), \cos(x), x$) with a much longer caption}{example-image-c}
\end{document}