4

In the figure below, I want to put the caption (method-1, method-2, method-3, method-4) on top-center of each respective plot and their numbering at bottom-center (as they are currently).

My Current figure:

enter image description here

Required Figure:

enter image description here

My Code:

\documentclass{article}
\usepackage{svg}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[margin=20, top=0.5, paperwidth=350px, paperheight=400px]{geometry}
\usepackage{caption} % Add the caption package


% Adjust the caption margin
\captionsetup{margin=10pt}

\begin{document}

\begin{figure}
  \centering
  \Large{\textbf{Figure Types}}  % Add the overall title as text
  
  \subfloat[method-1]{\includesvg[width=0.25\textwidth]{test.svg}\label{fig:ln}}\hfill
  \subfloat[method-2]{\includesvg[width=0.25\textwidth]{test.svg}\label{fig:ln}}\hfill
  \subfloat[method-3]{\includesvg[width=0.25\textwidth]{test.svg}\label{fig:ln}}\hfill
  \subfloat[method-4]{\includesvg[width=0.25\textwidth]{test.svg}\label{fig:ln}}
    
  \caption{This is an overall figure caption}
\end{figure}

\end{document}
1
  • Page size in units of px? LaTeX does not use pixels. For compatibility, 1px=1pt. Nov 5, 2023 at 16:47

3 Answers 3

4

Set each image construct in a tabular so you can structure them vertically - label at the top and image at the bottom.

enter image description here

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption} % Add the caption package

\begin{document}

\begin{figure}
  \centering
  \Large{\textbf{Figure Types}}  % Add the overall title as text
  
  \subcaptionbox{}{%
    \begin{tabular}{@{} c @{}}
      \small method-1 \\
      \includegraphics[width=0.2\textwidth]{example-image}
    \end{tabular}}\hfill
  \subcaptionbox{}{%
    \begin{tabular}{@{} c @{}}
      \small method-2 \\
      \includegraphics[width=0.2\textwidth]{example-image}
    \end{tabular}}\hfill
  \subcaptionbox{}{%
    \begin{tabular}{@{} c @{}}
      \small method-3 \\
      \includegraphics[width=0.2\textwidth]{example-image}
    \end{tabular}}\hfill
  \subcaptionbox{}{%
    \begin{tabular}{@{} c @{}}
      \small method-4 \\
      \includegraphics[width=0.2\textwidth]{example-image}
    \end{tabular}}
    
  \caption{This is an overall figure caption}
\end{figure}

\end{document}
5
  • My figures are in .svg format. With the above method, I am getting an exception in Overleaf, LaTeX Error: Unknown graphics extension: .svg.
    – skm
    Nov 4, 2023 at 17:53
  • @skm: The \includegraphics part of my solution is independent of yours. You can use your SVG images like you did in your original post. Since I don't have your SVG images, I used to basic example images supplied in all TeX distributions (from the mwe package) just so I can visualize it similarly to what you did.
    – Werner
    Nov 4, 2023 at 17:57
  • By replacing \includegraphics by \includesvg, it worked for me as well. Thanks a lot :)
    – skm
    Nov 4, 2023 at 17:59
  • Somehow the vertical spacing between the "caption on top and image-top" and "numbering and image-bottom" are not the same. How can I reduced the vertical spacing between "numbering and image-bottom"?
    – skm
    Nov 4, 2023 at 18:26
  • @skm: You can adjust this vertical gap via the skip option provided by subcaption. Try with \captionsetup[subfigure]{skip=0pt} in your preamble to remove any vertical skip by default for all subfigures. It'll be different if you're using subfig.
    – Werner
    Nov 4, 2023 at 18:44
1

Since you know the widths of the subfloats, you can create fake captions using \makebox.

\documentclass{article}
\usepackage{svg}
\usepackage{graphicx}
\usepackage{subfig}% see also subcaption
%\usepackage[margin=20px, top=0.5px, paperwidth=350px, paperheight=400px]{geometry}
\usepackage{caption} % Add the caption package

\usepackage{duckuments}% for variety

% Adjust the caption margin
\captionsetup{margin=10pt}

\begin{document}

\begin{figure}
  \centering
  \Large{\textbf{Figure Types}}  % Add the overall title as text
  
  {\footnotesize
  \makebox[0.25\textwidth]{method-1}\hfill
  \makebox[0.25\textwidth]{method-2}\hfill
  \makebox[0.25\textwidth]{method-3}\hfill
  \makebox[0.25\textwidth]{method-4}}
  
  \subfloat[]{\includegraphics[width=0.25\textwidth]{example-image-duck}\label{fig:ln}}\hfill
  \subfloat[]{\includegraphics[width=0.25\textwidth]{example-image-duck}\label{fig:ln}}\hfill
  \subfloat[]{\includegraphics[width=0.25\textwidth]{example-image-duck}\label{fig:ln}}\hfill
  \subfloat[]{\includegraphics[width=0.25\textwidth]{example-image-duck}\label{fig:ln}}
    
  \caption{This is an overall figure caption}
\end{figure}

\end{document}

demo

1

By use of tabularray package for organizing of images and \subfloats for inserting them in table:

\documentclass{article}
%\usepackage{svg}   % not used in this example since I haven't installed this package
\usepackage{graphicx}
\usepackage{subcaption} 
\usepackage{caption}    
\usepackage{tabularray} 
\UseTblrLibrary{counter}

\begin{document}

\begin{figure}
  \centering
  \Large{\textbf{Figure Types}}  % Add the overall title as text

\begin{tblr}{colspec = {@{} *{4}{X[c]} @{}}, 
             row{1}  = {font=\footnotesize},
             rowsep = 1pt
             }
method-1    & method-2  & method-3  & method-4      \\
\subfloat[\label{subfig:a}]{\includegraphics[width=\linewidth]{example-image-duck}}
    & \subfloat[\label{subfig:b}]{\includegraphics[width=\linewidth]{example-image-duck}}
        & \subfloat[\label{subfig:c}]{\includegraphics[width=\linewidth]{example-image-duck}}
            & \subfloat[\label{subfig:d}]{\includegraphics[width=\linewidth]{example-image-duck}} \\
\end{tblr}
  \caption{This is an overall figure caption}
  \label{fig:1}
\end{figure}
See image \subref{subfig:a} and \subref{subfig:c} in the figure \ref{fig:1} ...
\end{document}

enter image description here

You must log in to answer this question.

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