如何获得非浮动的图片网格,并为部分图片添加标题

如何获得非浮动的图片网格,并为部分图片添加标题

我真的很难做到这一点...我想从博客创建一本包含大约 5,000 张图片和文本的书。我编写了一个小转换器,从我从博客获得的 xml 文件创建有效的 tex 文件。

由于图片数量太多,我需要缩小它们的尺寸,并希望一行最多放 4 张图片。有时在下一个文本元素之前会有超过 30 张图片。在这种情况下,应该有某种可以扩展到几页的图片网格。图像应该是非浮动的,因为文本中没有任何实际参考...您只是根据它们的位置来了解含义。有些图片有一个标题,也应该显示出来。

因此,我尝试生成一个图像表,但发现即使使用“longtable”包,似乎也无法将表扩展到多个页面。这就是为什么我尝试为每一行图片创建一个表。我正在取得进展,但我无法让标题在非浮动表格环境中工作。

我已经尝试了几种选择,但似乎没有一种能满足我的所有要求。

\begin{center}
\begin{tabular}[c]{cccc}
\includegraphics[width=0.24\textwidth]{D:/Blogfotos3/wpid-p8220063.jpg}\captionof{figure}{Testing}&
\includegraphics[width=0.24\textwidth]{D:/Blogfotos3/wpid-p8220070.jpg}&
\includegraphics[width=0.24\textwidth]{D:/Blogfotos3/wpid-p8220092.jpg}
\end{tabular}
\end{center}

使用此解决方案,间距看起来相当好,但标题不起作用。

\begin{figure}[H]
\centering
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-img_7064.jpg}\end{subfigure}
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-dsc5085-edit.jpg}\caption{\centering Scorpionfish}\end{subfigure}
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-dsc5195-edit.jpg}\caption{\centering Schnegge}\end{subfigure}
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-dsc5236.jpg}\caption{\centering Noch ne Schnegge}\end{subfigure}
\end{figure}
\begin{figure}[H]
\centering
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-dsc5178.jpg}\caption{\centering Orang-utan-Crab}\end{subfigure}
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-dsc5022.jpg}\end{subfigure}
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-dsc5139.jpg}\end{subfigure}
\begin{subfigure}[t]{0.24\textwidth}\includegraphics[width=\textwidth]{D:/Blogfotos3/wpid-dsc5251.jpg}\caption{\centering Ghostpipefish}\end{subfigure}
\end{figure}

这里的标题确实有用,但我在放置位置上遇到了困难。我的意思是 H 迫使图片放在正确的位置,但有很多未使用的空白,我不希望这本书超过 500 页 ;-)

还有其他建议或套餐可以满足我的需求吗?

提前谢谢您,Flo

答案1

这将创建一个类似于以下内容的页面列表

在此处输入图片描述

我使用\captionof它来对带有标题的内容进行编号,您可以根据需要轻松调整对全部内容进行编号或不进行编号。

\documentclass{article}
\usepackage{capt-of,graphicx}
\newcounter{pics}

\newcommand\z[2][]{%
  \ifnum\value{pics}=4\par\setcounter{pics}{1}\else\stepcounter{pics}\fi
  \ifhmode\unskip\hfill\fi
  \parbox[t]{.23\textwidth}{%
   \centering\includegraphics[width=\linewidth]{#2}\par
   \ifx\relax#1\relax\else\captionof{figure}{#1}\fi}}
\errorcontextlines100
\begin{document}
\raggedright
\setlength\parskip{.5cm}
\z[zzz]{example-image}\z[hmmm]{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z[wwwwheeee]{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z[this...]{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z[a caption]{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z[caption]{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-b}\z{example-image-b}
\z{example-image}\z{example-image-b}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-a}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}
\z{example-image}\z{example-image-a}\z{example-image-b}


\end{document}

相关内容