1

I have a set of 13 figures. I display them 4 per row in a subfigure environment.

My code:

\usepackage{floatrow}
\floatsetup[figure]{subcapbesideposition=top}
\usepackage{graphicx}
\usepackage[label font=bf, 
            labelformat=simple]{subfig}
 \captionsetup[subfigure]{labelfont=rm}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}

    \begin{figure}[H]
    \centering
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}} 
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}} 
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \hfill
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \hfill
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \hfill
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}


\end{figure}

\end{document}

This yields captions below each figure, as in the image below:

captions generated

However, I would like the captions to be printed above each figure and give them a name instead of (a), (b), etc … Also, I need to reduce the spacings between each figure in a row.

2
  • i didn't realize floatrow supported \captonsetup and \subfloat. It really is a world unto itself. Commented Jun 18, 2022 at 0:33
  • I would suggest also looking into the subcaption package
    – jII
    Commented Jun 19, 2022 at 21:52

3 Answers 3

2

Add the position=top parameter to \captionsetup command.

The following is also updated to include the requests in comments: spreading out figures evenly horizontally and naming them without numbering. See comments in the code to see what command is responsible for what.

\documentclass{report}

\usepackage{floatrow}
\usepackage{graphicx}
\usepackage[labelformat=simple]{subfig}

% The following sets the label position to be above the figure
\captionsetup[subfigure]{position=top}

% The following disables numbering of labels (i.e., (a), (1), etc).
\renewcommand\thesubfigure{}

\begin{document}
    
    \begin{figure}[H]
        \centering
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill % <-- spreads out figure evenly horrizontally
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}} 
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \\ % <-- puts a manual line break
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}} 
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
    \end{figure}

\end{document}

enter image description here

6
  • but won't that affect the other figures in the document, which are in subfloat environment?
    – sphero
    Commented Jun 17, 2022 at 15:42
  • @sphero Yes. I was under impression you wanted it globally. Do you want me to update the answer to make captions on top per figure? Commented Jun 17, 2022 at 19:47
  • Bohatova no problem, i confused subfloat environment with the normal figure environment. just thought that captions will also be above the figures, which is something I do not wish.. but how do i replace the (a) (b) with a custom caption?
    – sphero
    Commented Jun 17, 2022 at 19:50
  • @sphero Do you want to change the numbering, like (1), (2), (3), or do you want to add text, like (a) figure 1, (b) figure 2, (c) figure 3 ? Commented Jun 17, 2022 at 19:56
  • i want to remove any (a) or (1) - just need to add text above each figure, I also still have a bit of space between figures, I want to have it like the example you generated, however, my figures are not wide at all as yours.
    – sphero
    Commented Jun 17, 2022 at 19:59
0

Your images can be organized in table, where in odd rows you insert image descriptions ("captions"), and in even rows images. For example, by use tabularray package for table, the code is:

\documentclass{report}
\usepackage{graphicx}
\usepackage{tabularray}

\begin{document}
    \begin{figure}[ht]
    \setkeys{Gin}{width=\linewidth}
\begin{tblr}{colsep=2pt,
             colspec={@{} *{4}{X[c]} @{}},
             row{even}={belowsep=1ex},
             row{odd}={rowsep=1 pt}
             }
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
 \end{tblr}
   \end{figure}
\end{document}

enter image description here

0

Since you don't really need \subfloat, you can just typeset the objects within a top aligned minipage (provided the descriptions don't overshoot the image width).

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]
\centering

\newcommand{\namedimage}[2]{%
  \begin{minipage}[t]{0.24\textwidth}
  \centering #1 \par\smallskip \includegraphics[width=\textwidth]{#2}
  \end{minipage}%
}
\newcommand{\inset}{\hspace{0.012\textwidth}}

\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\par\medskip

\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\par\medskip

\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\par\medskip

\namedimage{desc}{example-image}

\end{figure}

\end{document}

enter image description here

I locally defined \namedimage and \inset in order to ease input.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .