我有两组图像,水果和花卉 jpeg 图像,如 1.jpeg、2.jpeg、3.jpeg、4.jpeg 和 5.jpeg。我想把它们放进去tikzpicture
,不互相重叠。以下是代码-
\documentclass{standalone}
\usepackage{graphicx}
\usepackage{ifthen}
\usepackage{tikz}
\newcommand{\imgwidth}{0.3\linewidth}
\newcommand{\forloop}[5][1]%
{%
\setcounter{#2}{#3}%
\ifthenelse{#4}%
{#5%
\addtocounter{#2}{#1}%
\forloop[#1]{#2}%
{%
\value{#2}%
}%
{#4}{#5}%
}%
%Else
{%
}%
}%
\newcounter{count}
\newcounter{index}
\setcounter{index}{1}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\forloop[1]{count}{1}{\value{count} < 6}
{
\node[inner sep=0] at (\arabic{index},3,0) {\includegraphics[width=\imgwidth]{./flowers/\arabic{count}}};
\node[inner sep=0] at (\arabic{index},0,0) {\includegraphics[width=\imgwidth]{./fruits/\arabic{count}}};
\addtocounter{index}{4}
}
\draw (\arabic{index}*0.45,-2) node {Flowers and Fruits};
\end{scope}
\end{tikzpicture}
\end{document}
可以看出,代码不够健壮。有没有更好的方法来实现同样的效果 tikzpicture
?
答案1
A tcbraster
(来自tcolorbox
)使用起来很简单。只需决定每行要放多少张图片,该包就会完成剩下的工作。
\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{tcbraster}[blank, raster columns=5]
\tcbincludegraphics{example-image}
\tcbincludegraphics{example-image-A}
\tcbincludegraphics{example-image-B}
\tcbincludegraphics{example-image-C}
\tcbincludegraphics{example-image}
\tcbincludegraphics{example-image-A}
\tcbincludegraphics{example-image-B}
\tcbincludegraphics{example-image-C}
\tcbincludegraphics{example-image}
\tcbincludegraphics{example-image-A}
\tcbincludegraphics{example-image-B}
\tcbincludegraphics{example-image-C}
\tcbincludegraphics{example-image}
\tcbincludegraphics{example-image-A}
\tcbincludegraphics{example-image-B}
\tcbincludegraphics{example-image-C}
\end{tcbraster}
\end{document}