尝试获取 2 个图形,每个图形下都有标题,但仅算作一个图形
\begin{figure}
\begin{subfigure}{0.31\textwidth}
\includegraphics[scale=0.25]{B2B1}
\caption{First subfigure} \label{fig:1a}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}{0.31\textwidth}
\includegraphics[scale=0.25]{B2B2}
\caption{Second subfigure} \label{fig:1b}
\end{subfigure}
\caption{A figure that contains three subfigures} \label{fig:1}
\end{figure}
然而它不断出现在下一个级别(它说有 3 个子图,但实际上只有 2 个)
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage{amsthm}
\usepackage{float}
\usepackage[round]{natbib}
\usepackage{lastpage}
\usepackage{indentfirst}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{upgreek}
\usepackage{amssymb}
\usepackage[margin=0.9in, top=5.3em, bottom=5.3em]{geometry}
\usepackage{epstopdf}
\usepackage{enumerate}
\usepackage{mathtools, chngcntr}
\usepackage{url}
\usepackage{subfig}
\usepackage{subcaption}
\counterwithin{figure}{section}
\theoremstyle{definition}
\newtheorem{definition}[figure]{Definition}
\newtheorem{theorem}[figure]{Theorem}
\newtheorem{corollary}[figure]{Corollary}
\newtheorem{lemma}[figure]{Lemma}
\newtheorem{algorithm}[figure]{Algorithm}
\newtheorem{example}[figure]{Example}
\renewcommand{\footrulewidth}{1pt}
\newcommand{\R}{\mathbb{R}}
\renewcommand{\labelenumii}{\roman{enumii}}
答案1
对于两个独立的并排图形,可以minipage
在figure
环境中使用两个;对于两个子图,我建议使用subcaption
带有其subfigure
环境的包;这里有一个展示这两种方法的例子:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{image1}
\caption{A subfigure}
\label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{image1}
\caption{A subfigure}
\label{fig:sub2}
\end{subfigure}
\caption{A figure with two subfigures}
\label{fig:test}
\end{figure}
\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{image1}
\captionof{figure}{A figure}
\label{fig:test1}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{image1}
\captionof{figure}{Another figure}
\label{fig:test2}
\end{minipage}
\end{figure}
\end{document}
该demo
选项graphicx
仅用于使我的示例可供所有人编译;您不应该在实际代码中使用该选项。