请考虑这个MWE:
\documentclass[a4paper, landscape]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[most]{tcolorbox}
\newcommand\UseImage[1]{%
\IfFileExists{#1.jpg}%
{\includegraphics[scale=\ImageScale]{#1.jpg}}%
{\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}
% =======================================
% Input ===================================
\def\BottomTitle{Bottom Title}
\def\ImageScale{0.5}
\def\ImageLeft{\UseImage{SomeImageName-1}}
\def\ImageRight{\UseImage{SomeImageName-17}}
%
\newcommand{\PictureIndexStartsAt}{1}
\newcommand{\PictureIndexEndsAt}{16}
% =======================================
% =======================================
\begin{document}
% Page Box:
\begin{tcolorbox}[]
% Images:
\begin{tcbitemize}[raster columns=2, raster force size=false]
\tcbitem[remember as=LeftRasterbox, width=9cm] \ImageLeft
\tcbitem[remember as=RightRasterbox, width=9cm] \ImageRight
\end{tcbitemize} % remeber as=<name> for later TikZ-usage
%
\tcblower
\BottomTitle
\end{tcolorbox}
\begin{tikzpicture}
% ................ Here is more code that should be on every page, at the same spot
\end{tikzpicture}
\end{document}
您可以看到,如果文件存在,则应该打印左侧图像SomeImageName-1.jpg
,也应该打印右侧图像SomeImageName-17.jpg
在第 1 页。
换句话说,我们目前有:
SomeImageName-1.jpg
(第 1 页,左侧)SomeImageName-17.jpg
(第 1 页,右侧)
还有一些tikzpicture
代码需要打印在每一页上以及BottomTitle
里面的一些标题(比如例子中的)tcolorbox
,也需要打印在每一页上,从MWE中就可以理解。
现在的问题是:
如何循环这个,以便我们有以下内容:
SomeImageName-1.jpg
(第 1 页,左侧)SomeImageName-17.jpg
(第 1 页,右侧)SomeImageName-2.jpg
(第 2 页,左侧)SomeImageName-18.jpg
(第 2 页,右侧)...-3.jpg
(第 3 页......-19.jpg
(第 3 页...等等直到
-16.jpg
(第 16 页...等等直到
-32.jpg
(第 16 页...
简而言之:
如何进行循环,以便可以打印多页,每页加载 2 个图像,如上面的循环描述一样?
可能是
\foreach \i in {\PictureIndexStartsAt,...,\PictureIndexEndsAt}{
\def\iPlusConstant{\the\numexpr\i+16}
- 左边:
\includegraphics[width=\textwidth]{./Pictures/XYZ-\i.jpg}
- 正确的:
\includegraphics[width=\textwidth]{./Pictures/XYZ-\iPlusConstant.jpg}
\newpage
请问如何将其组合成与此 MWE 一起工作的循环?
答案1
\documentclass[]{article}
\usepackage[most]{tcolorbox}
\newcommand\UseImageLeft[1]{%
\IfFileExists{#1\i.jpg}%
{\includegraphics[scale=\ImageScale]{#1\i.jpg}}%
{\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}
\newcommand\UseImageRight[1]{%
\IfFileExists{#1\iPlusConstant.jpg}%
{\includegraphics[scale=\ImageScale]{#1\iPlusConstant.jpg}}%
{\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}
% Input ===================================
\def\ImageScale{0.2}
\def\ImageLeft{\UseImageLeft{Image-}}
\def\ImageRight{\UseImageRight{Image-}}
\newcommand{\PictureIndexStartsAt}{1}
\newcommand{\PictureIndexEndsAt}{16}
\def\iPlusConstant{\the\numexpr\i+16}
% =======================================
\begin{document}
\foreach \i in {\PictureIndexStartsAt,...,\PictureIndexEndsAt}{
% On any page (begin)
\begin{tcolorbox}[]
\begin{tcbitemize}[]
\tcbitem[] \ImageLeft
\tcbitem[] \ImageRight
\end{tcbitemize}
\end{tcolorbox}
% On any page (end)
\newpage
}
\end{document}