每个子图下的子标题未对齐

每个子图下的子标题未对齐

我目前有一个包含两个子图的图。我想在每个子图下添加标签,但无法对齐它们。从两个子图(即整个页面)的角度来看,第一个子标题似乎居中,这导致第二个子标题从我认为是新行的地方开始。更具体地说,我拥有的代码是:

\documentclass[10pt,journal,compsoc]{IEEEtran}

% *** SUBFIGURE PACKAGES ***
\ifCLASSOPTIONcompsoc
 \usepackage[caption=false,font=footnotesize,labelfont=sf,textfont=sf]{subfig}
\else
 \usepackage[caption=false,font=footnotesize]{subfig}
\fi
% subfig.sty, written by Steven Douglas Cochran, is the modern replacement
% for subfigure.sty, the latter of which is no longer maintained and is
% incompatible with some LaTeX packages including fixltx2e. However,
% subfig.sty requires and automatically loads Axel Sommerfeldt's caption.sty
% which will override IEEEtran.cls' handling of captions and this will result
% in non-IEEE style figure/table captions. To prevent this problem, be sure
% and invoke subfig.sty's "caption=false" package option (available since
% subfig.sty version 1.3, 2005/06/28) as this is will preserve IEEEtran.cls
% handling of captions.
% Note that the Computer Society format requires a sans serif font rather
% than the serif font used in traditional IEEE formatting and thus the need
% to invoke different subfig.sty package options depending on whether
% compsoc mode has been enabled.
%
% The latest version and documentation of subfig.sty can be obtained at:
% http://www.ctan.org/pkg/subfig

\usepackage{caption}
\usepackage{subcaption}


\begin{figure*}[!t]
    \begin{subfigure}
        \centering
        \includegraphics[trim={0, 0, 0, 0}, width=\columnwidth]{figures/plot1.pdf}
        \subcaption{Thing}
    \end{subfigure}
    \begin{subfigure}
        \centering
        \includegraphics[trim={0, 0, 0, 0}, width=\columnwidth]{figures/plot2.pdf}
        \subcaption{Thing}
    \end{subfigure}
\caption{Something.}
\label{fig:attention_score}
\end{figure*}

这就导致了: 在此处输入图片描述

我读过这个答案子图采用了子标题锚点的选项,因此我[c]在每个选项的右侧添加了一个\begin{subfigure}。结果如下: 在此处输入图片描述

这两张图片都不是我想要的。我应该如何配置才能让每个子标题都位于每个子图的正下方?谢谢。

答案1

您的 MWE 加载了subfig包,subcaption导致出现如下错误消息:

! Package subcaption Error: This package can't be used in cooperation with the subfig package.

为了解决这个问题,请删除subcaption包并使用\subfloat而不是subfigure环境,如下例所示:

在此处输入图片描述

\documentclass[10pt,journal,compsoc]{IEEEtran}

% *** SUBFIGURE PACKAGES ***
\ifCLASSOPTIONcompsoc
 \usepackage[caption=false,font=footnotesize,labelfont=sf,textfont=sf]{subfig}
\else
 \usepackage[caption=false,font=footnotesize]{subfig}
\fi

\usepackage[demo]{graphicx}% remove the demo option in your actual document.

\begin{document}


\begin{figure*}[!t]
\subfloat[Thing.]{\includegraphics[width=\columnwidth]{figures/plot1.pdf}}
\hfill
\subfloat[Thing.]{\includegraphics[width=\columnwidth]{figures/plot2.pdf}}
\caption{Something.}
\label{fig:attention_score}
\end{figure*}

\end{document}

答案2

您的测试文档必须生成以下类型的多条错误消息——不要忽视它们

./main.tex:10: Missing number, treated as zero.
<to be read again> 
\protect 
l.10         \centering
                     
? 

这些消息是由于您的代码中的语法错误而生成的:您未能提供强制性的宽度参数环境subfigure

如何修复此问题?\begin{subfigure}您不应只写 ,而应写\begin{subfigure}{\columnwidth}

一旦修复了这些语法错误,测试文档就可以直接编译。不过,为了增加代码的安全性,我会删除(或注释掉)两个冗余指令,并在两个环境之间\centering插入一个指令,以最大限度地扩大它们的水平分离。\hfillsubfigure

在此处输入图片描述

\documentclass[twocolumn]{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx} % remove 'demo' option in real document

\begin{document}

\begin{figure*}
    \begin{subfigure}{\columnwidth} % <-- added '{\columnwidth}'
        %\centering % redundant
        \includegraphics[trim={0, 0, 0, 0}, width=\columnwidth]{figures/plot1.pdf}
        \subcaption{Thing 1}
    \end{subfigure}%
    \hfill % <-- maximize horizontal separation (subject to text block width constraint)
    \begin{subfigure}{\columnwidth} % <-- added '{\columnwidth}'
        %\centering % redundant
        \includegraphics[trim={0, 0, 0, 0}, width=\columnwidth]{figures/plot2.pdf}
        \subcaption{Thing 2}
    \end{subfigure}
\caption{Something.}
\label{fig:attention_score}
\end{figure*}

\end{document}

答案3

在此处输入图片描述

\documentclass[12pt]{report}
\usepackage[letterpaper,top=1in,bottom=1in,right=1in,left=1in]{geometry}
    \usepackage[demo]{graphicx}
\usepackage{subcaption}
    \begin{document}
        \begin{figure}[h]
                    \begin{subfigure}[t]{0.45\textwidth}
                    \includegraphics[trim={0, 0, 0, 0}, width=\textwidth]{gfx-1}
                    \caption{Caption 1}
                \end{subfigure}
                \hfill
                    \begin{subfigure}[t]{0.45\textwidth}
                        \includegraphics[trim={0, 0, 0, 0}, width=\textwidth]{gfx-1}
                        \caption{Caption 2}
                    \end{subfigure}
        \caption{center caption}
        \end{figure}
    \end{document}

相关内容