我在 Google 上搜索并尝试了所有方法,我希望 4 张图片以 2x2 的形状显示在图形中。我使用了以下代码
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{figures/A_n100.jpeg}
\caption[]{{\small $A$ full}}
\label{fig:Afull}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{figures/B_n100.jpeg}
\caption[]{{\small $B$ full}}
\label{fig:Bfull}
\end{subfigure}
\vskip\baselineskip
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{figures/A_n100_zoomed.jpeg}
\caption[]{{\small $A$ zoomed in}}
\label{fig:Azoomed}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{figures/B_n100_zoomed.jpeg}
\caption[]{{\small $B$ zoomed in}}
\label{fig:Bzoomed}
\end{subfigure}
\caption{Tridiagonal shape of $A$ and $B$ for \texttt{n=100}}}
\label{fig:aenb}
\end{figure}
并包含以下软件包
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{subcaption}
\usepackage{subfigure}
但它就是不显示。我做错了什么?:(
答案1
让我阐明一下我的评论:
- 在您的代码片段中,主标题中有太多的闭合花括号。
- 软件包
subfig
、\subfigure
(已过时)和subcaption
不兼容。在您的代码片段中,您只使用了最后一个,因此请删除其他两个。
使用article
文档类,包含代码片段的 MWE(最小工作示例)应该是:
\documentclass{article}
\usepackage[demo]{graphicx} % in real document remove option "demo"
\usepackage{subcaption}
\begin{document}
\begin{figure}
%\captionsetup[subfigure]{font=small} if you like to change caption style
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{figures/A_n100.jpeg}
\caption[]{$A$ full} % <---
\label{fig:Afull}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{figures/B_n100.jpeg}
\caption[]{$B$ full} % <---
\label{fig:Bfull}
\end{subfigure}
\vskip\baselineskip
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{figures/A_n100_zoomed.jpeg}
\caption[]{$A$ zoomed in} % <---
\label{fig:Azoomed}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{figures/B_n100_zoomed.jpeg}
\caption[]{$B$ zoomed in} % <---
\label{fig:Bzoomed}
\end{subfigure}
\caption{Tridiagonal shape of $A$ and $B$ for \texttt{n=100}} % <---
\label{fig:aenb}
\end{figure}
\end{document}
哪里有<---
标记,哪里就是您的代码片段被更正的地方。
答案2
这符合你的要求吗
\documentclass{article}
% ========== Packages ==========
\usepackage{graphicx, geometry}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption[]{{\small $A$ full}}
\label{fig:Afull}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption[]{{\small $B$ full}}
\label{fig:Bfull}
\end{subfigure}
\vskip\baselineskip
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption[]{{\small $A$ zoomed in}}
\label{fig:Azoomed}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption[]{{\small $B$ zoomed in}}
\label{fig:Bzoomed}
\end{subfigure}
\caption{Tridiagonal shape of $A$ and $B$ for \texttt{n=100}}
\label{fig:aenb}
\end{figure}
\end{document}