将一个图形显示在另一个图形上方会导致标题/子标题包错误

将一个图形显示在另一个图形上方会导致标题/子标题包错误

我试图在一页上放置两个图形,一个在另一个之上:

\begin{figure}
    \centering
    \begin{subfigure}[b]
    \includegraphics[scale=1.00]{AB.png}
    \caption{A and B}
    \label{fig:AB}
    \end{subfigure}

    \begin{subfigure}[b]
    \includegraphics[scale=1.00]{CD.png}
    \caption{C and D}
    \label{fig:CD}
    \end{subfigure}
     \caption{Text of caption.}
\end{figure}

但是当我编译 LaTeX 时,收到以下信息:

("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\caption\subcaption.sty"

LaTeX Warning: You have requested, on input line 44, version
               `2012/03/25' of package caption,
               but only version
               `2004/05/16 v3.0b Customising captions (AS)'
               is available.

! Undefined control sequence.
l.45 \caption@AtBeginDocument
                             {\caption@ifcompatibility{%
? 

Process has been terminated ...

有人能提供建议吗?

文档LaTeX如下:

\documentclass[oneside,12pt]{report} % Use twoside for alternate page headings.


\usepackage{setspace}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{alltt}
\usepackage{anysize}
\usepackage{appendix}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{changepage}
% \usepackage{cite}
\usepackage{color}
\usepackage{enumerate}
\usepackage{etoolbox}
\usepackage{fancyhdr}
\usepackage{fixltx2e}
\usepackage{footmisc}
% \usepackage{graphics}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{ragged2e}
\usepackage{hyperref}
\usepackage{bookmark}
\usepackage[numbers,sort]{natbib}
\usepackage{url}
\usepackage[normalem]{ulem}
\usepackage{subcaption}

% \marginsize{2.54cm}{2.54cm}{2.54cm}{2.54cm}

% LIST OF ABBREVIATIONS. ---------------------------------------------------------------------------------------

\usepackage[acronym,footnote,nonumberlist]{glossaries} % Makes a list of abbreviations.
\usepackage{glossary-mcols}

\renewcommand{\glossarypreamble}{The abbreviations below\ldots}

% LIST OF ABBREVIATIONS. --------------------------------------------------------------------------

% NOTE: The LaTeX glossary is in file Abbreviations.tex. The thesis glossary is in file Glossary.tex.

% With thanks to: http://tex.stackexchange.com/questions/197692/adding-a-specific-title-to-
%                 list-of-abbreviations-acronyms-in-latex.

\usepackage[acronym,footnote,nonumberlist]{glossaries} % Makes a list of abbreviations.
\usepackage{glossary-mcols}
% \makeglossaries % This must be run from the command-line: e.g. 'makeglossaries file'
                  % where `file` is the name of the main LaTeX file.
\renewcommand{\glossarypreamble}{Some text\ldots}

\include{DummyAbbreviations}
% \renewcommand{\glsnamefont}[1]{\textbf{#1}}

\makeglossaries
\glossarystyle{mcolindex}
% \glossarystyle{long}

% PART, CHAPTER AND SECTION NUMBERING.  -----------------------------------------------------------------------------------------------------------------

\makeatletter

\let\LaTeXStandardPart\part%
\newcommand{\unstarredpart@@noopt}[1]{%
    \unstarredpart@@opt[#1]{#1}%
}

\newcommand{\unstarredpart@@opt}[2][]{%
    \cleardoublepage% (For clearing content before.)
    \begingroup%
    \let\newpage\relax%
    \LaTeXStandardPart[#1]{#2}%
    \endgroup%
}

\newcommand{\starredpart}[1]{%
    \LaTeXStandardPart*{#1}%
}

\newcommand{\unstarredpart}{%
    \@ifnextchar[{\unstarredpart@@opt}{\unstarredpart@@noopt}%
}

\renewcommand{\part}{%
  \@ifstar{\starredpart}{\unstarredpart}%
}

% BIBLIOGRAPHY PREAMBLE. --------------------------------------------------------------------------

\renewcommand{\bibpreamble}{The references below\ldots}

% BEGIN DOCUMENT. ---------------------------------------------------------------------------------

\begin{document}

    \pagenumbering{roman}

    % Title page.
    \title{Title}

    \begin{Huge}
    \noindent\textbf{TITLE}
    \end{Huge}


    % LISTINGS. ---------------------------------------------------------------------------------------

    \tableofcontents

    % Print glossary.
    \glsaddall
    \printglossary[type=acronym,title={List of Abbreviations}]
    \addcontentsline{toc}{chapter}{List of Abbreviations}
    % \printglossaries%[title={List of abbreviations}]

    % Print algorithms.
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{List of Algorithms}% Add contents entry for List of Tables
    \listofalgorithms% Start List of Tables
    \setcounter{chapter}{0}

    % Print figures.
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{List of Figures}% Add contents entry for List of Tables
    \listoffigures% Start List of Tables

    % Print tables.
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{List of Tables}% Add contents entry for List of Tables
    \listoftables% Start List of Tables

    \clearpage

    \pagenumbering{arabic}

    \chapter{Introduction}
    \emph{Text to go here\ldots}

    \begin{figure}
    \centering
    \begin{subfigure}[b]
    \includegraphics[scale=1.00]{DocsAndImages/AB.png}
    \caption{A and B}
    \label{fig:Ng1}
    \end{subfigure}

    \begin{subfigure}[b]
    \includegraphics[scale=1.00]{DocsAndImages/CD.png}
    \caption{C and D}
    \label{fig:Ng2}
    \end{subfigure}

    \caption{Text of caption.}
    \end{figure}

    \chapter{Chapter}
    \emph{Text to go here\ldots}

    \chapter{Conclusion}
    \emph{Text to go here\ldots}

    \appendix
    \chapter{Title}
    \emph{Text to go here\ldots}

    \bookmarksetupnext{level=-1}
    % Print figures.
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{Bibliography}% Add contents entry for List of Tables
    \bibliography{DummyBibliography1}
    \bibliographystyle{plain}

\end{document}

答案1

subcaption.sty提供环境subfiguresubtable。来自文档:

3 子图和子表环境

加载subcaption包后,新的环境 subfiguresubtable可用,它们具有与 minipage 环境相同的(可选和强制)参数:

\begin{subfigure}[<pos>]{<width>}
  . . .
\end{subfigure}

添加强制参数例如{0.5\linewidth}应该可以解决您的问题:

  \begin{subfigure}[b]{.5\linewidth}
    \includegraphics[scale=1.00]{AB.png}
    \caption{A and B}
    \label{fig:AB}
  \end{subfigure}

相关内容