0

Please consider this 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}

You can see, that, if the files exist, the left image should print SomeImageName-1.jpg and the right image should print SomeImageName-17.jpg on page 1.

In other words, we currently have:

  • SomeImageName-1.jpg (page 1, left)
  • SomeImageName-17.jpg (page 1, right)

There is also some more tikzpicture code which needs to be print on every page, as well as some titles (such as BottomTitle in the example) inside a tcolorbox, which also need to be print on every page, as can be understood from the MWE.

Now the question:

How to loop this, such that we have the following:

  • SomeImageName-1.jpg (page 1, left)

  • SomeImageName-17.jpg (page 1, right)

  • SomeImageName-2.jpg (page 2, left)

  • SomeImageName-18.jpg (page 2, right)

  • ...-3.jpg (p. 3 ...

  • ...-19.jpg (p. 3 ...

  • and so forth untill -16.jpg (p. 16 ...

  • and so forth untill -32.jpg (p. 16 ...

In short:

How to have a loop, such that multiple pages can be print, each loaded with 2 images per page, as per the loop description above?

Probably something with

  • \foreach \i in {\PictureIndexStartsAt,...,\PictureIndexEndsAt}{
  • \def\iPlusConstant{\the\numexpr\i+16}
  • LEFT: \includegraphics[width=\textwidth]{./Pictures/XYZ-\i.jpg}
  • RIGHT: \includegraphics[width=\textwidth]{./Pictures/XYZ-\iPlusConstant.jpg}
  • \newpage

How to piece this together into a loop which works with this MWE please?

0
\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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.