3

I have two set of images, fruits and flowers jpeg images like 1.jpeg, 2.jpeg, 3.jpeg, 4.jpeg and 5.jpeg. I want to put them in tikzpicture, without overlapping with each other. Below is the code-

\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}

As it can be seen that the code is not robust enough. Any better way to achieve the same using tikzpicture?

Below is the generated document- enter image description here

ravi
  • 1,618

1 Answers1

3

A tcbraster (from tcolorbox) is easy to use. Just decide how many images do you want on each row, and the package will do the rest.

\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}

enter image description here

Ignasi
  • 136,588
  • Cool enough. Can you please provide the manual for tcbraster? How to configure the margin, padding, caption etc? – ravi Jul 11 '16 at 09:12
  • 2
    @RaviJoshi Do you have tcolorbox installed on your system? If the asnwer is yes, type "texdoc tcolorbox" on a command window. In windows+miktex, I use "texdoc --view tcolorbox". As an alternative you can consult texdoc or CTAN – Ignasi Jul 11 '16 at 09:21
  • Thank you very much.. I really liked texdoc tcolorbox command. – ravi Jul 11 '16 at 10:11