我插入的图形占了一整页,它位于页面中间,上下有两个大的空白间隙。上一行的文本在上一页的底部附近结束,所以我假设图形将从下一页的顶部开始。以下是我写的内容:
\begin{figure}
\captionsetup[subfigure]{justification=centering}
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{images/a1.png}
\caption{a}
\label{subfig1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{images/a2.png}
\caption{b}
\label{subfig2}
\end{subfigure}
\caption[abc]{abc}
\label{fig1}
\end{figure}
当我在后面写文本时,文本\end{figure}
会出现在上一页,位于我在图形之前写的文本旁边。我希望图形出现在页面顶部,而我在图形之后写的任何文本都出现在图形下方。我试过了,\begin{figure}[h]
但\begin{figure}[t]
都不起作用。下面是发生的情况的图片,使用没有选项的报告文档类。
以下是所要求的“最小工作示例”:
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{array}
\usepackage{amsmath,amsthm}
\usepackage{cite}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[parfill]{parskip}
\usepackage{lipsum}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{theorem}{Theorem}[section]
\begin{document}
\begin{titlepage}
\centering
\vspace*{1cm}
\Huge
\textbf{Title}
\vspace{1.5cm}
\huge
\textbf{Author}
\vspace{5cm}
\Large
Supervised by Professor
\vspace{1cm}
\large
Department\\
University
\end{titlepage}
\addcontentsline{toc}{chapter}{Abstract}
\newpage
\chapter*{\centering Abstract}
\tableofcontents
\addcontentsline{toc}{chapter}{Introduction}
\listoffigures
\newpage
\chapter*{Introduction}
\newpage
\chapter{Chapter 1}
\lipsum[66]
\section{Section 1.1}
\lipsum[66]
\lipsum[67]
We can see that the following two properties hold:
\begin{enumerate}
\item Property 1
\item Property 2
\end{enumerate}
\section{Section 1.2}
\lipsum[66]
\begin{definition}[Definition 1]
etc.
\end{definition}
Example:\\
\[ \begin{array}{c|cccc}
\text{Bit}&2^3 &2^2 &2^1 &2^0\\ \hline
8 &1 &0 &0 &0\\
9 &1 &0 &0 &1\\ \hline
1 &0 &0 &0 &1\\ \hline
\end{array} \]
\lipsum[66]
Theorem below
\begin{theorem}
\label{thm1}
Theorem
\end{theorem}
\begin{proof}
Proof
\begin{flalign*}
s &= 0 \oplus s \nonumber \\
&= r \oplus r \oplus s && \text{(By first sentence)} \nonumber \\
&= r \oplus (a_1 \oplus a_2 \oplus \cdots \oplus a_n) \oplus
(b_1 \oplus b_2 \oplus \cdots \oplus b_n) \nonumber \\
&= r \oplus (a_1 \oplus b_1) \oplus \cdots \oplus (a_n \oplus b_n) \nonumber \\
&= r \oplus a_k \oplus b_k && \text{(Again by first sentence)} \nonumber
\end{flalign*}
\lipsum[66]
\begin{flalign*}
s &= r \oplus a_k \oplus b_k \nonumber &\\
&= r \oplus a_k \oplus r \oplus a_k \nonumber &\\
&= r \oplus r \oplus a_k \oplus a_k \nonumber &\\
&= 0 \nonumber
\end{flalign*}
\lipsum[66]
\end{proof}
\lipsum[66]
\chapter{Chapter 2}
\lipsum[66]
\section{Section 2.1}
\lipsum[66]
\lipsum[66]
\begin{figure}[ht] %
\captionsetup[subfigure]{justification=centering}
\centering
\setkeys{Gin}{width=\linewidth}%
\begin{subfigure}{.45\textwidth}%
\includegraphics{image.png}
\caption{a}
\label{subfig1}
\end{subfigure}%
\hfil
\begin{subfigure}{.45\textwidth}%
\centering
\includegraphics{image.png}
\caption{b}
\label{subfig2}
\end{subfigure}
\caption[abc]{abc}
\label{fig1}
\end{figure}
\bibliographystyle{plain}
\bibliography{refs}
\end{document}
答案1
将您的代码片段插入到简单的文章文档中
\documentclass{article}
\usepackage{caption, subcaption}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}
\begin{figure}
\captionsetup[subfigure]{justification=centering}
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{example-image-duck}
\caption{a}
\label{subfig1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{example-image-duck}
\caption{b}
\label{subfig2}
\end{subfigure}
\caption[abc]{abc}
\label{fig1}
\end{figure}
\lipsum[1]
\end{document}
我得到以下结果:
因此,不清楚您在实际文档中做了什么。显然您应该提供一个 MWE(最小工作示例),以重现您所声称的内容。
不过,我希望您的图像采用以下格式:
其中 MWE 为:
\documentclass{article}
\usepackage{caption, subcaption}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}
\lipsum[66]
\begin{figure}[ht] % <---
\captionsetup[subfigure]{justification=centering}
\centering
\setkeys{Gin}{width=\linewidth} % <---
\begin{subfigure}{.45\textwidth} % <---
\includegraphics{example-image-duck}%{images/a1.png}
\caption{a}
\label{subfig1}
\end{subfigure}%
\hfil
\begin{subfigure}{.45\textwidth} % <---
\centering
\includegraphics{example-image-duck}%{images/a1.png}
\caption{b}
\label{subfig2}
\end{subfigure}
\caption[abc]{abc}
\label{fig1}
\end{figure}
\lipsum[1]
\end{document}
与您的代码片段相比,差异以 标记<---
。