4

I have several images and I must put their names below them. Moreover, I need to give the name of the group of that images too (for example, "first layer", "second layer" ect as show below). I need to have something as shown in the figure below.

image

IMPORTANT: In my case, a group of images may contain more than one row. I mean, the "(a) first layer" may contain more than 3 images and hence can be a group of images in more than one row.

Gonzalo Medina
  • 505,128
skm
  • 960
  • The question is answered here: http://tex.stackexchange.com/questions/132599/placement-of-images-in-row-using-subfigure – rvaneijk Jul 27 '15 at 21:37
  • @rvaneijk: Actually in my case, a group of images may contain more than one row. – skm Jul 27 '15 at 21:40

2 Answers2

3

Two options:

  1. Using some tabulars for each layer and the subcaption package:

    enter image description here

    The code:

    \documentclass{article}
    \usepackage{subcaption}
    \usepackage{graphicx}
    
    \begin{document}
    
    \begin{figure}
    \begin{minipage}{\linewidth}
      \centering
      \begin{tabular}{ccc}
      \includegraphics[width=.28\linewidth,height=1cm]{example-image-a}
        & \includegraphics[width=.28\linewidth,height=1cm]{example-image-b}
        & \includegraphics[width=.28\linewidth,height=1cm]{example-image-c} \\
      First image & Second image & Third image \\  
      \includegraphics[width=.28\linewidth,height=1cm]{example-image-a}
        & \includegraphics[width=.28\linewidth,height=1cm]{example-image-b} \\
      Fourth image & Fifth image &
      \end{tabular}
      \subcaption{First layer}
      \end{minipage}\par\bigskip
      \begin{minipage}{\linewidth}
      \centering
      \begin{tabular}{ccc}
      \includegraphics[width=.28\linewidth,height=1cm]{example-image-a}
        & \includegraphics[width=.28\linewidth,height=1cm]{example-image-b}
        & \includegraphics[width=.28\linewidth,height=1cm]{example-image-c} \\
      First image & Second image & Third image \\  
      \end{tabular}
      \subcaption{Second layer}
      \end{minipage}
    \caption{a figure with some layers of subfigures each with its own name and each layer with a subcaption}
    \end{figure}
    
    \end{document}
    

    Above I used a standard tabular with three c type columns; if the text below the images should span more than one line, you could use tabularx from the tabularx package and centered X columns, as the option below illustrates.

  2. Since the OP is using subfig, the subcaption package cannot be used; here's an approach using the same idea as before, but with tabularx and the subfig package:

    \documentclass{article}
    \usepackage[caption=false]{subfig}
    \usepackage{graphicx}
    \usepackage{tabularx}
    
    \newcolumntype{Y}{>{\centering\arraybackslash}X}
    
    \begin{document}
    
    \begin{figure}
    \subfloat[First layer]{%
    \begin{minipage}{\linewidth}
      \centering
      \begin{tabularx}{\linewidth}{YYY}
      \includegraphics[width=\linewidth,height=1cm]{example-image-a}
        & \includegraphics[width=\linewidth,height=1cm]{example-image-b}
        & \includegraphics[width=\linewidth,height=1cm]{example-image-c} \\
      First image & Second image & Third image \\  
      \includegraphics[width=\linewidth,height=1cm]{example-image-a}
        & \includegraphics[width=\linewidth,height=1cm]{example-image-b} \\
      Fourth image & Fifth image &
      \end{tabularx}
      \end{minipage}}\par\medskip
    \subfloat[Second layer]{%
      \begin{minipage}{\linewidth}
      \centering
      \begin{tabularx}{\linewidth}{YYY}
      \includegraphics[width=\linewidth,height=1cm]{example-image-a}
        & \includegraphics[width=\linewidth,height=1cm]{example-image-b}
        & \includegraphics[width=\linewidth,height=1cm]{example-image-c} \\
      First image & Second image & Third image \\  
      \end{tabularx}
      \end{minipage}}
    \caption{a figure with some layers of subfigures each with its own name and each layer with a subcaption}
    \end{figure}
    
    \end{document}
    

    enter image description here

Gonzalo Medina
  • 505,128
  • It throws an error Undefined control sequence. \subcaption because I am already using \usepackage[caption = false]{subfig} – skm Jul 27 '15 at 22:10
  • 1
    @skm You should have mentioned that in the first place! subcaption and subfig are incompatible. In some minutes I'll update my answer using subfig instead. – Gonzalo Medina Jul 27 '15 at 22:12
  • Actually, I am already using \usepackage[caption = false]{subfig} and hence I cannot use \usepackage{subcaption} in combination to it – skm Jul 27 '15 at 22:12
  • @skm Please see the updated answer under the "Update" section. – Gonzalo Medina Jul 27 '15 at 22:16
  • The method works but the name of the group for example "(a) first layer", "(b) Second Layer" are in smaller font than the name of individual images. This seems a little strange. Is there any solution for this problem? – skm Jul 27 '15 at 22:26
  • 2
    @skm If you want normal size for the subcaptions load the subfig package like this: \usepackage[caption=false,font=normalsize]{subfig}. The other option is to use something like \small First image & \small Second image... inside the table to reduce the font size for the image names. – Gonzalo Medina Jul 27 '15 at 22:36
  • thanks a lot. It is something which I have been looking for a long time. Thanks a lot. – skm Jul 27 '15 at 22:41
  • @skm You're welcome. Glad I could help. – Gonzalo Medina Jul 27 '15 at 22:52
  • Your suggestion worked but actually I have several images in a figure and hence now these images are getting hide behind the bottom of the page. I am facing a similar situation which I faced here http://tex.stackexchange.com/questions/245689/page-break-between-images-of-a-figure – skm Jul 30 '15 at 20:51
0

You can have multiple rows, e.g. look at this example from ClassicThesis:

begin{figure}[bth]
    \myfloatalign
    \subfloat[Asia personas duo.]
    {\includegraphics[width=.45\linewidth]{gfx/example_1}} \quad
    \subfloat[Pan ma signo.]
    {\label{fig:example-b}%
     \includegraphics[width=.45\linewidth]{gfx/example_2}} \\
    \subfloat[Methodicamente o uno.]
    {\includegraphics[width=.45\linewidth]{gfx/example_3}} \quad
    \subfloat[Titulo debitas.]
    {\includegraphics[width=.45\linewidth]{gfx/example_4}}
    \caption[Tu duo titulo debitas latente]{Tu duo titulo debitas
    latente.}\label{fig:example}
\end{figure}
rvaneijk
  • 330