我正在尝试使用子标题来显示两个对齐的图像。这是我的代码
\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=.4\linewidth]{Figures/fig.png}
\caption{1a}
\label{fig:sfig1}
\end{subfigure}%
\begin{subfigure}[b]{.3\textwidth}
\includegraphics[width=.4\linewidth]{Figures/fig.png}
\caption{1b}
\label{fig:sfig2}
\end{subfigure}
\caption{plots of....}
\label{fig:fig}
\end{figure}
\end{document}
除了一件事之外,一切都正常:子图的宽度未注册。每当我编译它时,0.4 都会出现在文档上,而不是被注册为因子。这是结果:
过去一个小时里,我一直在网上寻找一些答案,每个人都建议使用与我相同的代码行。我是不是漏掉了什么?
答案1
编辑:。我不清楚你认为你的代码有什么问题。如果你希望标题和子标题居中于属于图像,则需要添加,\centering
如下面的代码所示。否则,“缩放”将按预期工作。为了看到这一点,我在第一个子图中添加了规则宽度长度\linewidth
。
\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}
\begin{document}
\begin{figure}[h]
\centering%<---
\begin{subfigure}[b]{0.3\textwidth}
\centering%<---
\rule{\linewidth}{1pt}
\includegraphics[width=.4\linewidth]{example-image-a}
\caption{1a}
\label{fig:sfig1}
\end{subfigure}%
\begin{subfigure}[b]{.3\textwidth}
\centering%<---
\includegraphics[width=.4\linewidth]{example-image-b}
\caption{1b}
\label{fig:sfig2}
\end{subfigure}
\caption{plots of....}
\label{fig:fig}
\end{figure}
\end{document}
我在代码中添加了包showframe
,以便页面上的图形位置更清晰可见。这是您要找的吗?我无法通过代码重现您的图像。