如何将标题放在图表顶部?

如何将标题放在图表顶部?

在下图中,我想要将标题(方法 1、方法 2、方法 3、方法 4)放在每个相应图的顶部中心,并将其编号放在底部中心(如当前所示)。

我目前的身材:

在此处输入图片描述

所需圖片:

在此处输入图片描述

我的代码:

\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

设置每个图像构造,tabular以便您可以垂直构造它们 - 标签在顶部,图像在底部。

在此处输入图片描述

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

答案2

由于您知道子浮点数的宽度,因此您可以使用创建虚假标题\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}

演示

答案3

通过使用tabularray包来组织图像并将\subfloat其插入表格中:

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

在此处输入图片描述

相关内容