当图形以不同的顺序显示时,如何修复图形编号?

当图形以不同的顺序显示时,如何修复图形编号?

我有这个问题,因为我要求的是出现顺序,所以问题解决了。但是,解决方案又给我带来了一个新问题:这些图的编号错误,即第一个图的标题是图 2,最后一个图是图 1。我该如何解决这个问题?

\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 previos question
\begin{landscape}%<--- Created first
\begin{figure}
\centering
\includegraphics[height=12cm]{example-image-a}
\caption{Example image a (must be Figure 1)}%<--- Figure 1
\end{figure}
\end{landscape}
\restorefloats}%<--- Solution previos question
\blindtext\par
\blindtext\par
\begin{figure}[htb]%<--- Created second
\centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{Example image b (must be Figure 2)}%<--- Figure 2
\end{figure}
\blindtext\par
\end{document}

相关内容