自动将子图拆分到多页

自动将子图拆分到多页

我有很多子图,我想将它们拆分到多个页面中。这些子图的大小不同。我仍在编辑文档,因此图被推来推去。我不想硬性规定子图之间的分页符在哪里。

我怎么能够:

  1. 当前页面已满时是否自动获取子图来开始新页面?
  2. 仅在开始新页面时添加标题?
  3. 防止其他内容在子图之间移动?

以下是我当前文档的一个示例。如您所见,\ContinueFloat 是硬连线的。其他内容位于前 5 个子图和后 5 个子图之间。

\begin{figure}
\centering
\subfloat[]{\label{fig:1}\includegraphics[width=0.43\textwidth]{fig1}}
\qquad
\subfloat[]{\label{fig:2}\includegraphics[width=0.43\textwidth]{fig2}}
\subfloat[]{\label{fig:1}\includegraphics[width=0.43\textwidth]{fig1}}
\qquad
\subfloat[]{\label{fig:2}\includegraphics[width=0.43\textwidth]{fig2}}
\qquad
\subfloat[]{\label{fig:1}\includegraphics[width=0.43\textwidth]{fig1}}
\qquad
\caption{Here are the first 5 figures of a continued figure.}
\label{fig:cont}
\end{figure}

\begin{figure}
\ContinuedFloat
\centering
\subfloat[]{\label{fig:1}\includegraphics[width=0.43\textwidth]{fig1}}
\qquad
\subfloat[]{\label{fig:2}\includegraphics[width=0.43\textwidth]{fig2}}
\qquad
\subfloat[]{\label{fig:1}\includegraphics[width=0.43\textwidth]{fig1}}
\qquad
\subfloat[]{\label{fig:2}\includegraphics[width=0.43\textwidth]{fig2}}
\qquad
\subfloat[]{\label{fig:1}\includegraphics[width=0.43\textwidth]{fig1}}
\caption{Here are the last 5 figures of a continued figure.}
\label{fig:cont}
\end{figure}

答案1

有趣的是,\subfloat似乎以 结尾\ignorespaces,因此您要么需要一个空白行,\allowbreak要么需要其他允许换行的内容。所有子浮点数都是一次性格式化的,因此\ContinuedFloat不需要。

我可以使用 udbox 将其转变为一个环境(参见https://tex.stackexchange.com/questions/563109/render-captions-above-figures-with-caption-below-includegraphics-while-using-e/563241?r=SearchResults&s=2|22.2526#563241)。

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{lipsum}

\let\bottomfraction=\topfraction
\let\floatpagefraction=\topfraction

\makeatletter
\newif\if@firstpageoffigure
\newcommand{\multipagefigure}[3]% #1 = caption, #2 = caption (cont.), #3 = contents
{\bgroup
  \def\@captype{figure}% enable captions
  \setbox2=\vbox{\caption{#1}}%
  \setbox3=\vbox{\addtocounter{figure}{-1}\caption{#2}}%
  \setbox0=\vbox{#3}%
  \@firstpageoffiguretrue
  \loop\ifvoid0\else    
    \if@firstpageoffigure
      \@firstpageoffigurefalse
      \dimen0=\dimexpr \pagegoal-\pagetotal-\textfloatsep\relax
      \ifdim\dimen0>\bottomfraction\textheight
        \dimen0=\bottomfraction\textheight
      \fi
      \setbox1=\copy0% compute smallest possible figure
      \setbox4=\vsplit1 to 0pt
      \setbox1=\vbox{\unvbox4}% restore true size
      \ifdim\dimen0<\dimexpr \ht1+\dp1+\ht2+\dp2\relax
        \dimen0=\textheight
      \fi
      \setbox1=\vsplit0 to \dimexpr \dimen0-\ht2-\dp2\relax
      \begin{figure}[bp]
        \unvbox1
        \unvbox2
      \end{figure}
    \else
      \setbox1=\vsplit0 to \dimexpr \textheight-\ht3-\dp3\relax
      \begin{figure}[tp]
        \unvbox1
        \usebox3
      \end{figure}
    \fi
  \repeat
\egroup}
\makeatother
    
\begin{document}

\lipsum[1-2]

\multipagefigure{Every page\label{fig:cont}}{Every page (cont.)}{%
\centering
\subfloat[]{\label{fig:1}\includegraphics[width=0.43\textwidth]{example-image-a}}\hfil
\subfloat[]{\label{fig:2}\includegraphics[width=0.43\textwidth]{example-image-b}}

\subfloat[]{\label{fig:3}\includegraphics[width=0.43\textwidth]{example-image-a}}\hfil
\subfloat[]{\label{fig:4}\includegraphics[width=0.43\textwidth]{example-image-b}}

\subfloat[]{\label{fig:5}\includegraphics[width=0.43\textwidth]{example-image-a}}\hfil
\subfloat[]{\label{fig:6}\includegraphics[width=0.43\textwidth]{example-image-b}}

\subfloat[]{\label{fig:7}\includegraphics[width=0.43\textwidth]{example-image-a}}\hfil
\subfloat[]{\label{fig:8}\includegraphics[width=0.43\textwidth]{example-image-b}}

\subfloat[]{\label{fig:9}\includegraphics[width=0.43\textwidth]{example-image-a}}\hfil
\subfloat[]{\label{fig:10}\includegraphics[width=0.43\textwidth]{example-image-b}}

\subfloat[]{\label{fig:11}\includegraphics[width=0.43\textwidth]{example-image-a}}\hfil
\subfloat[]{\label{fig:12}\includegraphics[width=0.43\textwidth]{example-image-b}}

\subfloat[]{\label{fig:13}\includegraphics[width=0.43\textwidth]{example-image-a}}\hfil
\subfloat[]{\label{fig:14}\includegraphics[width=0.43\textwidth]{example-image-b}}
}
\lipsum[3-6]

\end{document}

相关内容