横向图形和普通图形中的显示顺序

横向图形和普通图形中的显示顺序

我正在处理一个包含大量图形的文本,其中一些是横向的。在文本中,我创建了一个横向图形,然后是一些段落,然后是一个常规图形。我预计横向图形会先出现,然后是常规图形,但事实并非如此。我怎样才能将横向图形放在第一个位置?我已经测试了 afterpage 命令

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[%
    left=3.00cm,
    right=2.00cm,
    top=3.00cm,
    bottom=2.00cm
]{geometry}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{pdflscape}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{afterpage}
\begin{document}
\blindtext\par
\blindtext\par
\blindtext\par
\afterpage{%
\begin{landscape}%<--- Created first
\begin{figure}
\centering
\includegraphics[height=12cm]{example-image-a}
\caption{Example image a}
\end{figure}
\end{landscape}
}
\blindtext\par
\blindtext\par
\begin{figure}[htb]%<--- Created second
\centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{Example image b}
\end{figure}
\blindtext\par
\end{document}

在此处输入图片描述

编辑1:

我使用了@JohnKormylo 的建议,它有效。但是,图形编号的顺序不正确。我该如何解决?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[%
    left=3.00cm,
    right=2.00cm,
    top=3.00cm,
    bottom=2.00cm
]{geometry}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{pdflscape}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{afterpage}
\makeatletter%<---@JohnKormylo's suggestion
\newcommand{\savefloats}{%
  \global\let\old@toplist=\@toplist
  \global\let\old@midlist=\@midlist
  \global\let\old@botlist=\@botlist
  \global\let\old@deferlist=\@deferlist
  \global\let\old@dbltoplist=\@dbldtoplist
  \global\let\old@dbldeferlist=\@dbldeferlist
  \global\let\@toplist=\@empty
  \global\let\@midlist=\@empty
  \global\let\@botlist=\@empty
  \global\let\@deferlist=\@empty
  \global\let\@dbltoplist=\@empty
  \global\let\@dbldeferlist=\@empty
  \xdef\old@colroom{\the\@colroom}
  \xdef\old@toproom{\the\@toproom}
  \xdef\old@botroom{\the\@botroom}
  \xdef\old@topnum{\the\@topnum}
  \xdef\old@botnum{\the\@botnum}
}
\newcommand{\restorefloats}{%
  \global\let\@toplist=\old@toplist
  \global\let\@midlist=\old@midlist
  \global\let\@botlist=\old@botlist
  \global\let\@deferlist=\old@deferlist
  \global\let\@dbltoplist=\old@dbltoplist
  \global\let\@dbldeferlist=\old@dbldeferlilst
  \global\@colroom=\old@colroom\relax
  \global\@toproom=\old@toproom\relax
  \global\@botroom=\old@botroom\relax
  \global\@topnum=\old@topnum\relax
  \global\@botnum=\old@botnum\relax
  \global\vsize=\@colroom
}
\makeatother
\begin{document}
\blindtext\par
\blindtext\par
\blindtext\par
\afterpage{\savefloats%<--- Solution
\begin{landscape}%<--- Created first
\begin{figure}
\centering
\includegraphics[height=12cm]{example-image-a}
\caption{Example image a (must be Figure 1)}
\end{figure}
\end{landscape}
\restorefloats}%<--- Solution
\blindtext\par
\blindtext\par
\begin{figure}[htb]%<--- Created second
\centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{Example image b (must be Figure 2)}
\end{figure}
\blindtext\par
\end{document}

在此处输入图片描述

答案1

浮点数总是按执行顺序排列,但\afterpage只是将其内容存储为标记,因此如果您这样做,横向图形就会在正常图形之后显示。(\afterpage非常脆弱,您只能将其用作最后的手段)

您可以使用sidewaysfigure旋转的图形像平常一样浮动。

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[%
    left=3.00cm,
    right=2.00cm,
    top=3.00cm,
    bottom=2.00cm
]{geometry}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{rotating}
\usepackage{blindtext}
\begin{document}
\blindtext\par
\blindtext\par
\blindtext\par

\begin{sidewaysfigure}
\centering
\includegraphics[height=12cm]{example-image-a}
\caption{Example image a}
\end{sidewaysfigure}

\blindtext\par
\blindtext\par
\begin{figure}[htbp]%<--- Created second (don't forget p :-)
\centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{Example image b}
\end{figure}
\blindtext\par
\end{document}

答案2

我结合了\savefloats\restorefloats这里\savebox之前的相同。

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[%
    left=3.00cm,
    right=2.00cm,
    top=3.00cm,
    bottom=2.00cm
]{geometry}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{pdflscape}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{afterpage}

\makeatletter
\newcommand{\setcaptype}[1]{\def\@captype{#1}}

\newcommand{\savefloats}{% this is probably overkill, but better safe than sorry
  \global\let\old@toplist=\@toplist
  \global\let\old@midlist=\@midlist
  \global\let\old@botlist=\@botlist
  \global\let\old@deferlist=\@deferlist
  \global\let\old@dbltoplist=\@dbldtoplist
  \global\let\old@dbldeferlist=\@dbldeferlist
  \global\let\@toplist=\@empty
  \global\let\@midlist=\@empty
  \global\let\@botlist=\@empty
  \global\let\@deferlist=\@empty
  \global\let\@dbltoplist=\@empty
  \global\let\@dbldeferlist=\@empty
  \xdef\old@colroom{\the\@colroom}% store as macros
  \xdef\old@toproom{\the\@toproom}% store as macros
  \xdef\old@botroom{\the\@botroom}% store as macros
  \xdef\old@topnum{\the\@topnum}% store as macros
  \xdef\old@botnum{\the\@botnum}% store as macros
}
\newcommand{\restorefloats}{%
  \global\let\@toplist=\old@toplist
  \global\let\@midlist=\old@midlist
  \global\let\@botlist=\old@botlist
  \global\let\@deferlist=\old@deferlist
  \global\let\@dbltoplist=\old@dbltoplist
  \global\let\@dbldeferlist=\old@dbldeferlilst
  \global\@colroom=\old@colroom\relax
  \global\@toproom=\old@toproom\relax
  \global\@botroom=\old@botroom\relax
  \global\@topnum=\old@topnum\relax
  \global\@botnum=\old@botnum\relax
  \global\vsize=\@colroom
}
\makeatother

\newsavebox{\lsfigure}

\begin{document}
\blindtext\par
\blindtext\par
\blindtext\par
\savebox{\lsfigure}{% increment figure/caption counter
  \begin{minipage}{\textheight}
  \setcaptype{figure}\centering
  \includegraphics[height=12cm]{example-image-a}
  \caption{Example image a}
  \end{minipage}}%
\afterpage{\savefloats
  \begin{landscape}%<--- Created first
  \begin{figure}
  \usebox{\lsfigure}
  \end{figure}
  \end{landscape}
  \restorefloats}%
\blindtext\par
\blindtext\par
\begin{figure}[htb]%<--- Created second
\centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{Example image b}
\end{figure}
\blindtext\par
\end{document}

相关内容