如何在不使用浮点数的情况下获得与子图等效的结果?

如何在不使用浮点数的情况下获得与子图等效的结果?

我理解花车应该漂浮但是,我有很多图形数据,有时当我说把它放在这里时,我的意思是准确地说,而不是加/减两页。

我可以使用 minipages 实现这一点,但它的标题不够清晰(见下面的最小工作示例)。有人能给我一个看起来与子图完全一样但不浮动的解决方法吗?

我知道我最终的文档不是很漂亮,但是它表达出了要点。

\documentclass{article} % Article class of KOMA-script with 11pt font and a4 format
\usepackage[pdftex]{graphicx}                                                       % Enable pdflatex
\usepackage{caption} %for images
\usepackage{subcaption} %for sub images

\begin{document}
\section{Doesn't float but not as pretty}
\subsection{A}
The below image details what results we got for subsection A

\centering
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test I}
 \end{minipage} ~ %
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test II}
 \end{minipage}

\subsection{B}
The below image details what results we got for subsection B

\centering
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test I}
 \end{minipage} ~ %
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test II}
 \end{minipage}

\subsection{C}
The below image details what results we got for subsection C

\centering
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test I}
 \end{minipage} ~ %
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test II}
 \end{minipage}

\subsection{D}
The below image details what results we got for subsection D

\centering
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test I}
 \end{minipage} ~ %
 \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/fov.pdf}
     \captionof{figure}{Test II}
 \end{minipage}

\section{Pretty, but keeps floating}
\subsection{A}
The below image details what results we got for subsection A

\begin{figure}[h!]
   \centering
   \begin{subfigure}[b]{0.5\textwidth} 
      \includegraphics[width=\textwidth]{images/fov.pdf} 
      \caption{Test I} 
   \end{subfigure}
   \begin{subfigure}[b]{0.5\textwidth}
      \includegraphics[width=\textwidth]{images/fov.pdf}
      \caption{Test II}
   \end{subfigure}
   \caption{Results for subsection A}
\end{figure}

\subsection{B}
The below image details what results we got for subsection B

\begin{figure}[h!]
   \centering
   \begin{subfigure}[b]{0.5\textwidth} 
      \includegraphics[width=\textwidth]{images/fov.pdf} 
      \caption{Test I} 
   \end{subfigure}
   \begin{subfigure}[b]{0.5\textwidth}
      \includegraphics[width=\textwidth]{images/fov.pdf}
      \caption{Test II}
   \end{subfigure}
   \caption{Results for subsection B}
\end{figure}

\subsection{C}
The below image details what results we got for subsection C

\begin{figure}[h!]
   \centering
   \begin{subfigure}[b]{0.5\textwidth} 
      \includegraphics[width=\textwidth]{images/fov.pdf} 
      \caption{Test I} 
   \end{subfigure}
   \begin{subfigure}[b]{0.5\textwidth}
      \includegraphics[width=\textwidth]{images/fov.pdf}
      \caption{Test II}
   \end{subfigure}
   \caption{Results for subsection C}
\end{figure}

\subsection{D}
The below image details what results we got for subsection D

\begin{figure}[h!]
   \centering
   \begin{subfigure}[b]{0.5\textwidth} 
      \includegraphics[width=\textwidth]{images/fov.pdf} 
      \caption{Test I} 
   \end{subfigure}
   \begin{subfigure}[b]{0.5\textwidth}
      \includegraphics[width=\textwidth]{images/fov.pdf}
      \caption{Test II}
   \end{subfigure}
   \caption{Results for subsection D}
\end{figure}

\end{document}

答案1

我不建议制作不浮动的图形。没错,标题只是为了向读者展示图形的内容。

但是,这里有一种方法可以解决您的问题:定义一个环境,在其中设置子图标题的格式(否则由于某种原因,它不会被设置)。

\documentclass{article} % Article class of KOMA-script with 11pt font and a4 format

\usepackage[demo]{graphicx}
\usepackage{caption} %for images
\usepackage{subcaption} %for sub images

\newenvironment{nonfloat}
  {%
   \par\nopagebreak\vspace{\medskipamount}%
   \noindent\begin{minipage}{\linewidth}
   \captionsetup[subfigure]{
     margin=0pt,font+=small,labelformat=parens,labelsep=space,
     skip=-6pt,list=false,hypcap=false
   }%
  }
  {\end{minipage}}

\begin{document}
\section{Doesn't float but not as pretty}
\subsection{A}
The below image details what results we got for subsection A

\begin{nonfloat}
\centering
\begin{minipage}{0.45\textwidth}
  \centering
  \includegraphics[width=\textwidth]{images/fov.pdf}
  \captionof{subfigure}{Test I}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
  \centering
  \includegraphics[width=\textwidth]{images/fov.pdf}
  \captionof{subfigure}{Test II}
\end{minipage}
\captionof{figure}{Results for subsection A}
\end{nonfloat}

\section{Pretty, but keeps floating}
\subsection{A}
The below image details what results we got for subsection A

\begin{figure}[!ht]
\centering
\begin{subfigure}[b]{0.45\textwidth} 
  \includegraphics[width=\textwidth]{images/fov.pdf} 
  \caption{Test I} 
\end{subfigure}\hfill
\begin{subfigure}[b]{0.45\textwidth}
  \includegraphics[width=\textwidth]{images/fov.pdf}
  \caption{Test II}
\end{subfigure}
\caption{Results for subsection A}
\end{figure}

\end{document}

在此处输入图片描述

注意:pdftex永远不应为 指定该选项graphicx(也不应该为 指定hyperref);我使用它demo只是因为我没有您的图形文件,所以将其从生产版本中删除。

答案2

尝试使用包提供的图形选项 [H] float

\documentclass{article} 
\usepackage[pdftex]{graphicx}
\usepackage{caption} %for images
\usepackage{subcaption} %for sub images
\usepackage{float} %for figure option H

\begin{document}
\section{Doesn't float but not as pretty}
\subsection{A}
The below image details what results we got for subsection A
    \begin{figure}[H]
\begin{subfigure}[b]{0.5\textwidth}\centering
    \includegraphics[width=0.9\hsize]{example-image}
    \caption{Test I}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}\centering
  \includegraphics[width=0.9\hsize]{example-image}
  \caption{Test II}
\end{subfigure}
   \caption{Results for subsection A}
    \end{figure}
\subsection{A}
The below image details what results we got for subsection B
    \begin{figure}[H]
\begin{subfigure}[b]{0.5\textwidth}\centering
    \includegraphics[width=0.9\hsize]{example-image}
    \caption{Test I}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}\centering
  \includegraphics[width=0.9\hsize]{example-image}
  \caption{Test II}
\end{subfigure}
   \caption{Results for subsection B}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容