4

It's not difficult to put a matrix of images.

For example, in such a derectory

    .
├── document.tex
├── pictures
│   ├── CellA
│   │   ├── p1.JPG
│   │   ├── p2.JPG
│   │   ├── p3.JPG
│   │   └── p4.JPG
│   ├── CellB
│   │   ├── p1.JPG
│   │   ├── p2.JPG
│   │   ├── p3.JPG
│   │   └── p4.JPG

..........

I can get thisexample by such code

\begin{figure}
    \begin{subfigure}{1.0cm}
        \centering\large Cell Name
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \caption{p1}
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \caption{p2}
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \caption{p3}
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \caption{p4}
    \end{subfigure}

    \begin{subfigure}{1.0cm}
        \centering\large Cell A
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \includegraphics[width=2.5cm]{pictures/CellA/p1.JPG}
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \includegraphics[width=2.5cm]{pictures/CellA/p2.JPG}
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \includegraphics[width=2.5cm]{pictures/CellA/p3.JPG}
    \end{subfigure}
    \begin{subfigure}{2.5cm}
        \includegraphics[width=2.5cm]{pictures/CellA/p4.JPG}
    \end{subfigure}         

\end{figure}

However, I have about 20 cells, so it is hard to repead these sentences. Is there a way to add this matrix of images in bulk?

  • Is it always 20 cells? Do you always want them in 4 columns? Can we assume the filenames are always p1 through p20? – Mike Renfro Sep 29 '15 at 16:16

1 Answers1

2
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz} % for \foreach
\usepackage{subcaption}

\begin{document}
\begin{figure}
  \begin{minipage}{1.0cm}%
    \centering Cell Name%
  \end{minipage}%
  \foreach \n in {1,...,4} {%
  \begin{minipage}{2.5cm}%
    \centering \subcaption{p\n}%
  \end{minipage}%
  }%

\foreach \x in {A,...,E} {%
  \begin{minipage}{1.0cm}%
    \centering Cell \x%
  \end{minipage}%
  \foreach \n in {1,...,4} {%
    \begin{minipage}{2.5cm}%
      \centering \includegraphics[width=2.5cm]{pictures/Cell\x/p\n}%
    \end{minipage}%
  }%

}
\end{figure}
\end{document}

enter image description here

Mike Renfro
  • 20,550
  • It's not guaranteed that filenames are always from p1 to p20. But it's fine, as we can set it manually \foreach \n in {p1,p2,p3,p4}. Thank you very much – Endle_Zhenbo Sep 30 '15 at 08:32