有时对某个图表的讨论会跨越数页,而我想在讨论继续进行时在每个偶数页上插入该图表的副本。
有一个与此密切相关的问题(每页后插入一张图片) 但所需的效果是在前言中设置一张图片,并将其插入到整个文档的每个偶数页中。而我想根据需要对不同的图形进行这种插入,即我需要一个宏来告诉在偶数页上包含哪个图形,直到我发出另一个宏,说插入现在必须结束。
我的 MWE 如下,但我只表达了我所追求的。我对如何继续下去一无所知。
有什么建议么?
\documentclass[12pt]{amsbook}
\usepackage{mwe,lipsum}
\begin{document}
\includegraphics[width=0.5\textwidth]{example-image-a}
%
% Now I want "example-image-a", or a re-scaled smaller version, to be inserted at the beginning of every even numbered page until the end of \lipsum or until I say so.
%
%
\lipsum[1-18]
%
\includegraphics[width=0.5\textwidth]{example-image-b}
%
% Now I want "example-image-b", or a re-scaled smaller version, to be inserted at the beginning of every even numbered page until the end of \lipsum or until I say so.
%
%
\lipsum
%
\end{document}
答案1
如果您对所指的解决方案感到满意,除了您提到的功能之外,还有一个简单的解决方法:制作图片宏,然后进行调整。
\documentclass{article}
\usepackage{afterpage,everypage}
\usepackage{mwe,lipsum}
\AddEverypageHook{%
\ifodd\value{page}
\OddPicture%
\else%
\EvenPicture%
\fi}
\afterpage{\includegraphics{example-image-a}} % why this is necessary?
\newcommand{\OddPicture}{}
\newcommand{\EvenPicture}{\afterpage{\includegraphics{example-image-a}}}
\newcommand{\StopPictures}{%
\renewcommand{\OddPicture}{}
\renewcommand{\EvenPicture}{}
}
\begin{document}
\lipsum[1-18]
\StopPictures
\lipsum
\renewcommand{\OddPicture}{\afterpage{\includegraphics{example-image-b}}}
\renewcommand{\EvenPicture}{}
\lipsum
\lipsum
\StopPictures
\lipsum
\end{document}
此代码片段导致文档在偶数页上暂时显示 example-image-a,然后切换到奇数页上的 example-image-b。
答案2
从 everypage 包中读到“...一旦钩子被堆叠,就没有办法取消堆叠,也没有办法清除它们。...条件必须包含在钩子中”我想出了以下解决方案:
\documentclass[12pt]{amsbook}
\usepackage{afterpage,everypage}
\usepackage{mwe,lipsum}
\usepackage{sidenotes}
\usepackage[dvipsnames]{xcolor} % For this example only
\AddEverypageHook{%
\ifodd\value{page}
\else%
\EvenPicture%
\fi}
\newcommand{\Picture}{}
\newcommand{\EmptyPicture}{}
\newcounter{permission}
\setcounter{permission}{0}
\afterpage{\ifnum\value{permission}=1%
\begin{center}%
{\includegraphics[width=0.5\textwidth]{\Picture}}
\end{center}%
\else\EmptyPicture\fi}
% This is needed for the first time \EvenPicture is called
\newcommand{\EvenPicture}{{\afterpage{\ifnum\value{permission}=1%
\begin{center}%
{\includegraphics[width=0.5\textwidth]{\Picture}}%
\end{center}%
\else\EmptyPicture\fi}}}
\newcommand{\StartPicture}[1]{%
\renewcommand{\Picture}{#1}%
\begin{center}\includegraphics{#1}\end{center}%
\setcounter{permission}{1}%
}
\newcommand{\StopPicture}{\setcounter{permission}{0}}
\begin{document}
\lipsum[1-3]
\StartPicture{example-image-a}
\lipsum[2-13]
\StopPicture
\textcolor{red}{We terminate figure A here}
\textcolor{green}{Now we start figure B}
\StartPicture{example-image-b}
\lipsum[3-19]
\StopPicture
\textcolor{red}{We terminate figure B here}
\lipsum[1]
\textcolor{green}{Now we start figure C}
\StartPicture{example-image-c}
\lipsum[4-11]
\StopPicture
\textcolor{red}{We terminate figure C here}
\lipsum[5-15]
\end{document}