我有一个关于这个主题的问题:将所有浮动元素放在最后,不改变编号
我该如何修改解决方案,使其适用于图表,包括图表列表?我已尝试使用该软件包endfloat
处理图表,但遇到了一些问题,因此我正在寻找一种替代方法,将所有图表放在文档末尾但在补充材料之前的单独章节中。
是否有可能在表格格式中包含多个图形?
\begin{figure*}
\centering
\begin{tabular}{lc}
%Input image&
\includegraphics[width=1cm]{example-image}&
\includegraphics[width=1cm]{example-image}\\
%Aligned face&
\includegraphics[width=1cm]{example-image-a}&
\includegraphics[width=1cm]{example-image-a}\\
\end{tabular}}{Fifth image}{fig:tabfig}
\end{figure*}
答案1
您可以维护一个堆栈,其中累积了用于创建浮点数的令牌。
在下面的例子中
通过 创建令牌堆栈。
\NewStack{⟨macro⟩}
标记通过以下方式附加到标记堆栈。
\AppendToStack{⟨macro⟩}{⟨tokens⟩}
堆栈中保存的标记将被“刷新”,并通过 清空堆栈。
\FlushAndClearStack{⟨macro⟩}
命令
\StuffAndCountersToStack{⟨macro⟩}% {⟨counters to step at the time of carrying out \StuffAndCountersToStack⟩}% {⟨counters to reset and restore at the time of delivering the ⟨tokens⟩⟩}% {⟨tokens⟩}%
添加到堆栈⟨宏⟩
- 打开本地范围的指令
- 重置指令⟨计数器在交付时重置和恢复⟨代币⟩⟩,
- 重置 \the 的指令⟨柜台⟩和 \theH⟨柜台⟩的⟨计数器在交付时重置和恢复⟨代币⟩⟩,
- 指令调整\⟨柜台⟩和 \theH⟨柜台⟩的⟨执行 \StuffAndCountersToStack 时要步进的计数器⟩
- ⟨代币⟩
- 恢复指令⟨计数器在交付时重置和恢复⟨代币⟩⟩,
- 关闭本地范围的指令
和步骤⟨执行 \StuffAndCountersToStack 时要步进的计数器⟩。
命令
\VerbatimToScantokensStuffAndCountersToStack{⟨macro⟩}% {⟨counters to step at the time of carrying out \StuffAndCountersToStack⟩}% {⟨counters to reset and restore at the time of delivering the ⟨verbatimized material⟩ via \scantokens⟩}% |⟨verbatimized material⟩|%
功能与命令 几乎相同
\StuffAndCountersToStack
。不同之处在于:⟨代币⟩-argument 在 verbatim-catcode-régime 中被读取和标记,因此被调用⟨逐字材料⟩. 而不是仅仅添加⟨代币⟩到堆栈⟨宏⟩,指令被添加到堆栈⟨宏⟩通过⟨逐字材料⟩到\scantokens
。
\makeatletter
% With older LaTeX-releases uncomment the following line:
%\RequirePackage{xparse}
\ExplSyntaxOn
\@ifdefinable\MapCommaListToMacro{%
\let\MapCommaListToMacro=\clist_map_function:nN
}%
\ExplSyntaxOff
\@ifdefinable\stopromannumeral{\chardef\stopromannumeral=`\^^00}%
\newcommand\unexpandedlocalsetcounter[1]{%
\unexpanded{\localsetcounter{#1}}{\number\value{#1}}%
\def\expandafter\noexpand\csname theH#1\endcsname{\csname theH#1\endcsname}%
\def\expandafter\noexpand\csname the#1\endcsname{\csname the#1\endcsname}%
}%
\newcommand\unexpandedadjustcounter[1]{%
\def\expandafter\noexpand\csname theH#1\endcsname{\csname theH#1\endcsname}%
\def\expandafter\noexpand\csname the#1\endcsname{\csname the#1\endcsname}%
}%
\newcommand\unexpandedsetcounter[1]{%
\unexpanded{\setcounter{#1}}{\number\value{#1}}%
}%
\@ifdefinable\localsetcounter{%
\DeclareRobustCommand\localsetcounter[2]{%
\csname c@#1\endcsname=#2\relax
}%
}%
\@ifdefinable\localstepcounter{%
\newcommand\localstepcounter[1]{%
\advance\csname c@#1\endcsname by 1 %
}%
}%
\newcommand\PassFirstToSecond[2]{#2{#1}}%
\newcommand\Exchange[2]{#2#1}%
%
% If this was for a package, checking whether stack-macro is defined
% could be implemented for the sake of error-checking.
\NewDocumentCommand\NewStack{m}{\newcommand#1{}}%
\NewDocumentCommand\FlushAndClearStack{m}{#1\global\let#1\empty}%
\NewDocumentCommand\AppendToStack{mm}{\xdef#1{\unexpanded\expandafter{#1#2}}}%
\newcommand\StuffAndCountersToStack[4]{%
\@bsphack
\begingroup
\protected@edef\@tempa{\MapCommaListToMacro{#3}{\unexpandedlocalsetcounter}}%
\MapCommaListToMacro{#2}{\localstepcounter}%
\protected@edef\@tempb{\MapCommaListToMacro{#2}{\unexpandedadjustcounter}}%
\expandafter\endgroup\expandafter\PassFirstToSecond\expandafter{%
\romannumeral
\expandafter\Exchange\expandafter{\expandafter{\expandafter\begingroup
\romannumeral\expandafter\expandafter\expandafter\stopromannumeral\expandafter
\@tempa\@tempb#4}}{%
\stopromannumeral
\begingroup
\protected@edef\@tempa{\MapCommaListToMacro{#3}{\unexpandedsetcounter}}%
\expandafter\endgroup\expandafter\Exchange\expandafter{\@tempa}%
}%
\endgroup
}{\AppendToStack{#1}}%
\MapCommaListToMacro{#2}{\stepcounter}%
\@esphack
}%
%=== \VerbatimToScantokensStuffAndCountersToStack ========================
\NewDocumentCommand\VerbatimToScantokensStuffAndCountersToStack{mmm}{%
\@bsphack
\begingroup
\catcode`\^^I=12\relax
\InnerVerbatimToScantokensStuffAndCountersToStack{#1}{#2}{#3}%
}%
\begingroup
\def\InnerVerbatimToScantokensStuffAndCountersToStack#1{%
\endgroup
\NewDocumentCommand\InnerVerbatimToScantokensStuffAndCountersToStack{mmm+v}{%
\endgroup
\expandafter\@gobble\StuffAndCountersToStack{##1}{##2}{##3}{%
\begingroup\newlinechar=\endlinechar
\scantokens{\endgroup##4#1}%
}%
}%
}%
\catcode`\%=12\relax
\InnerVerbatimToScantokensStuffAndCountersToStack{%}%
%=== End of code of \VerbatimToScantokensStuffAndCountersToStack =========
\makeatother
\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
% Load hyperref _after_ float !
\usepackage{hyperref}
\NewStack{\laterfloats}
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\csname @ifundefined\endcsname{theHfigure}{}{%
\renewcommand{\theHfigure}{\theHsection.\arabic{figure}}%
}%
\csname @addtoreset\endcsname{figure}{section}
% \ref without hyperlink:
\csname @ifpackageloaded\endcsname{hyperref}{%
\newcommand*\myref{\ref*}%
}{%
\newcommand*\myref{\ref}%
}%
\begin{document}
\listoffigures
\section*{Introduction}
Please see figure~\ref{fig:one} and \ref{fig:two} and \ref{fig:three}
and \ref{fig:four} in Appendix~\ref{app:allimg}.
\section{First section}
Delayed figure~\ref{fig:one} and delayed figure~\ref{fig:two} are defined in this section.
\StuffAndCountersToStack{\laterfloats}{figure}{section,figure}{%
\begin{figure}[H]
\centering
\includegraphics[width=50pt]{example-image-a}%
\caption{First image}%
\label{fig:one}%
\end{figure}%
}%
\StuffAndCountersToStack{\laterfloats}{figure}{section,figure}{%
\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{example-image-b}%
\caption{Second image}%
\label{fig:two}%
\end{figure}%
}%
\section{Second section}
Delayed figure~\ref{fig:three} is defined in this section.
\VerbatimToScantokensStuffAndCountersToStack{\laterfloats}%
{figure}%
{section,figure}%
?%<-start of verbatim-argument
\begin{figure}[H]
\centering
\begin{tabular}{|c|}
\hline\\
\begin{minipage}{.27\textwidth}
% Indenting of source code does matter with verbatimized arguments!
\begin{verbatim*}
1 AB % & _^~# } {
2 AB % & _^~# } {
\end{verbatim*}
\end{minipage}
\\\\\hline
\end{tabular}
\caption{figure with verbatim}%
\label{fig:three}%
\end{figure}%
? %<-end of verbatim-argument
\section{Third section}
Delayed figure~\ref{fig:four} is defined in this section.
\StuffAndCountersToStack{\laterfloats}{figure}{section,figure}{%
\begin{figure}[H]
\centering
\includegraphics[height=240pt]{example-image-c}%
\caption{Third image}%
\label{fig:four}%
\end{figure}%
}%
\appendix
\section{An appendix}\label{app:a}
\begin{figure}[H]
\centering
A figure in appendix \myref{app:a}
\caption{A figure in appendix \myref{app:a}}
\end{figure}
\subsection{A subsection of appendix \myref{app:a}}\label{app:allimg}
Here come all the delayed floats.
\FlushAndClearStack{\laterfloats}
\end{document}
我认为 expl3 中只有几行,但是我对 expl3 还不够熟悉,无法在几分钟内输入适当的 expl3 代码。
这里有许多 expl3 的杰出人物,我无法与他们相比,他们当然会做得比我好得多,而我只能花几个小时摆弄和阅读 interface3.pdf。
但我“借用”了 expl3 \clist_map_function:nN
来将逗号列表的元素映射为宏的参数。;-)
(我也有自己的“老式代码”来处理这类事情,但将其粘贴到这里意味着另一堆令人困惑的代码。)
答案2
尝试一下这个代码。
更新开始用 .1 对每个部分的数字进行编号。
使用环境中的命令figfrom
(一个可选参数和三个必需参数:
#1
(opt)图形配置、#2
图形名称、#3
标题、标签)将所有图形移动到末尾#4
fromsection{<section number of the figures>}
\documentclass[a4paper]{article}
%%***************** adapted from <<<<<<<<<<<<<<<<<<
%% https://tex.stackexchange.com/questions/3491/place-all-floats-last-without-changing-numbering
\usepackage{graphicx}
\usepackage{float}
\newcounter{savesection}
\newenvironment{fromsection}[1]{% #1 section number
\setcounter{figure}{0}%
\setcounter{savesection}{\value{section}}%
\setcounter{section}{#1}%
\renewcommand{\thesection}{\arabic{section}}}
{\setcounter{section}{\value{savesection}}}
\newcommand{\figfrom}[4][]{% #1 (opt) figure specs, #2 figure name, #3 caption, #4 label
\begin{figure}[H]
\centering
\includegraphics[#1]{#2}
\caption{#3}
\label{#4}
\end{figure}
}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
%% *****************************************
\begin{document}
\listoffigures
\section{Introduction}
Please see figures~\ref{fig:one} and \ref{fig:two} in section~\ref{app:allimg}.
\section{Other stuff}
See also figure~\ref{fig:three} on page~\pageref{fig:three}.
\section{All figures together}\label{app:allimg}
\begin{fromsection}{1}
\figfrom[width=50pt]{example-image-a}{First image}{fig:one}
\figfrom[scale=0.5]{example-image-b}{Second image}{fig:two}
\end{fromsection}
\begin{fromsection}{2}
\figfrom[height=270pt]{example-image-c}{Third image}{fig:three}
\end{fromsection}
\appendix
\section{Supplement}
\end{document}