Probably doing calculation in terms of \number\numexpr...\relax does work out for you?
% arara: pdflatex
% arara: pdflatex
% arara: pdflatex
\documentclass[a4paper, landscape]{article}
\pagestyle{empty}
\usepackage[showframe=false,
margin=20mm,
]{geometry}
%\geometry{paperwidth=15cm, paperheight=30cm, margin=2mm}% optional
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfkeys{/tikz/savevalue/.code 2 args={\global\edef#1{#2}}}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\usepackage[most]{tcolorbox}
\tcbset{
NoGaps/.style={boxsep=0mm, left=0pt, right=0pt, top=0pt, bottom=0pt, before skip=0pt, after skip=0pt,},
%
CommonStyle/.style={sharp corners,
enhanced, % allows TikZ etc.
colback=white,
boxrule=0mm, % 0.5mm = default
colframe=white, %frame hidden,
},
%
RasterStyle/.style={
raster equal skip=\SeperationBetweenImages,
raster equal height=rows,
raster halign=center, raster valign=center,
},
}
\newcommand\NiceForEachElement{}%
% WHY TWO DIFFERENT COMMANDS \UseImageLeft AND \UseImageRight
% WHICH DO EXACTLY THE SAME?
\newcommand\UseImageLeft[2]{%
% #1 preceding phrase "image-"
% #2 number of image
\IfFileExists{#1#2.jpg}%
{\includegraphics[scale=\ImageScale]{#1#2.jpg}}%
{\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}
\newcommand\UseImageRight[2]{%
% #1 preceding phrase "image-"
% #2 number of image
\IfFileExists{#1#2.jpg}%
{\includegraphics[scale=\ImageScale]{#1#2.jpg}}%
{\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}
% Input ============
\xdef\author{The Author}
\def\TopTitleLeft{Object-0001}
\def\TopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
\def\TopTitleRight{Picture 1 of 16}
\def\TopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
\def\BottomTitle{\textcopyright~\author}
\def\ImageScale{0.7}
%
% WHY TWO DIFFERENT COMMANDS \ImageLeft AND \ImageRight
% WHICH DO EXACTLY THE SAME?
%
\newcommand\ImageLeft[1]{\UseImageLeft{Image-}{#1}}
\newcommand\ImageRight[1]{\UseImageRight{Image-}{#1}}
\pgfmathsetlengthmacro{\u}{15.07425pt}% unitlength
%
\def\ShowHelps{0} % 1 'yes' 0 'no'
% Input ============
\ifnum\ShowHelps=1
\pagecolor{lightgray!22} % see page margins
\def\HelpBoxRule{5.7pt}
\def\HelpGap{0mm}
\tcbset{ShowHelps/.style={boxrule=\HelpBoxRule, colframe=#1},
ShowHelps/.default={black},
}
\pgfmathsetlengthmacro{\SeperationBetweenImages}{1.18cm}
\else
\def\HelpBoxRule{5.7pt}
\pgfmathsetlengthmacro{\SeperationBetweenImages}{1.18cm+\HelpBoxRule+\HelpBoxRule}
\def\HelpBoxRule{0mm}
\def\HelpGap{0mm}
\tcbset{ShowHelps/.style=,} \fi
\newcommand\TopTitle{%
\begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=\large\bfseries,
raster columns=100, % Trick: '100 percent'...
]
\tcbitem[raster multicolumn=23, halign=left] \TopTitleLeft
\tcbitem[raster multicolumn=54, halign=center] \TopTitleMiddle
\tcbitem[raster multicolumn=23, halign=right] \TopTitleRight
\end{tcbitemize}}
% Definition of Image Ruler x
\newcommand\xRuler[5]{
\path let \p1=($(#1)-(#2)$) in
\pgfextra{ \pgfmathsetlengthmacro{\RasterboxesWidth}{veclen(\x1,\y1)} }
[savevalue={\w}{\RasterboxesWidth}];
\pgfmathsetmacro\NoXdiv{\w/\u} % Number of x dividions
\draw[Ruler] (#1) coordinate(X) -- (#2);
\foreach \n in {0,1,...,\NoXdiv}{%%
\draw[Ruler] ([xshift=\n\u]X) -- +(0,#4) node[#3, inner sep=1pt]{\ifnum\n=1 \n,cm \else \n\fi};
}%%
\foreach \n in {0.1,0.2,...,\NoXdiv}{%%
\draw[] ([xshift=\n\u]X) -- +(0,#5);
}%%
}
% Definition of Image Ruler y
\def\ifzero{1} % show zero
\newcommand\yRuler[5]{
\path let \p1=($(#1)-(#2)$) in
\pgfextra{ \pgfmathsetlengthmacro{\RasterboxesHeight}{veclen(\x1,\y1)} }
[savevalue={\h}{\RasterboxesHeight}];
\pgfmathsetmacro\NoYdiv{\h/\u} % Number of y dividions
\draw[Ruler] (#1) coordinate(Y) -- (#2);
\foreach \n in {0,1,...,\NoYdiv}{%%
\draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0) node[#3, inner sep=1pt]{
\ifnum\n=0 \ifnum\ifzero=1 \n \fi%
\else%
\ifnum\n=1 \n,cm%
\else \n%
\fi\fi};
}%%
\foreach \n in {0.1,0.2,...,\NoYdiv}{%%
\draw[] ([yshift=\n\u]Y) -- +(#5,0);
}%%
}
% Definition of Image Ruler y BIS
\def\ifzero{1} % show zero
\newcommand\yRulerBis[5]{
\path let \p1=($(#1)-(#2)$) in
\pgfextra{ \pgfmathsetlengthmacro{\RasterboxesHeight}{veclen(\x1,\y1)} }
[savevalue={\h}{\RasterboxesHeight}];
\pgfmathsetmacro\NoYdiv{\h/\u} % Number of y dividions
\draw[Ruler] (#1) coordinate(Y) -- (#2);
\foreach \n in {0,1,...,\NoYdiv}{%%
\ifnum\n=1 \ifdim#4>0pt \draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0) node[#3, inner sep=1pt]{\n,cm};% 1cm (from left image): bar + text
\else
\draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0);\fi% 1cm (from right image): bar
\else
\ifdim#4>0pt \draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0) node[#3, inner sep=1pt, minimum width=2.15em]{\n};% all numbers lower than 10 (from left image), excluding 1: bar + text
\else
\draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0);\fi;% all numbers (from right image), excluding 1: bar
\fi;
};
\foreach \n in {0.1,0.2,...,\NoYdiv}{%%
\draw[] ([yshift=\n*\u]Y) -- +(#5,0);
}%%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEFINITION OF CONSTANT DENOTING THE DIFFERENCE BETWEEN INDEX
% OF IMAGE AT THE LEFT AND INDEX OF IMAGE AT THE RIGHT:
\newcommand\IndexDifference{16}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Adding \IndexDifference to a given number:
\newcommand\AddIndexdifference[1]{%
\number\numexpr(#1)+(\IndexDifference)\relax
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
% outside the loop the width of Image-7.jpg or example-image.jpg:
\pgfmathsetlengthmacro\LeftWidth{width("\noexpand\noexpand\noexpand\ImageLeft{7}")}%
%\show\LeftWidth
\pgfmathsetlengthmacro\RightWidth{width("\noexpand\noexpand\noexpand\ImageRight{7}")}%
%\show\LeftWidth
\pgfmathsetlengthmacro\RightWidth{width("\noexpand\noexpand\noexpand\ImageRight{\AddIndexdifference{7}}")}%
%\show\LeftWidth
% inside the loop:
\foreach \NiceForEachElement in {1,...,3}{%
\pgfmathsetlengthmacro\LeftWidth{width("\noexpand\noexpand\noexpand\ImageLeft{\NiceForEachElement}")}%
\pgfmathsetlengthmacro\RightWidth{width("\noexpand\noexpand\noexpand\ImageRight{\AddIndexdifference{\NiceForEachElement}}")}%
% \show\LeftWidth
% Page Box:
\begin{tcolorbox}[CommonStyle, ShowHelps=red,
NoGaps, % top=3mm,
valign=center, halign=center, % Box content to page center
height=\textheight,
%Top Title ==========================
title=\TopTitle,
finish={
\node[align=left, anchor=north west] at (title.south west){\TopTitleLeftBelow};
},
% Bottom Title ========================
space to upper,
lower separated=false
]
% Images:
\begin{tcbitemize}[CommonStyle, RasterStyle, NoGaps, ShowHelps=cyan,
raster columns=2, %boxsep=\HelpGap,
halign=center, valign=center,
raster left skip=-1mm, raster right skip=-1mm,% not needed
raster force size=false, %size=tight,
]
\tcbitem[remember as=LeftRasterbox, ShowHelps=pink,
width=\LeftWidth+\HelpBoxRule+\HelpBoxRule+\HelpGap+\HelpGap] \ImageLeft{\NiceForEachElement}%
\tcbitem[remember as=RightRasterbox,
width=\RightWidth+\HelpBoxRule+\HelpBoxRule+\HelpGap+\HelpGap] \ImageRight{\AddIndexdifference{\NiceForEachElement}}%
\end{tcbitemize}
\tcblower
\BottomTitle
\end{tcolorbox}
\begin{tikzpicture}[overlay,remember picture,
Ruler/.style={thick},
Help/.style={|-|, very thick, yellow!77!orange, fill, text=red, inner sep=0.5pt, align=left},
]
\pgfmathsetlengthmacro\hbr{(\HelpBoxRule+0*\HelpGap)}
\coordinate[shift={(\hbr,\hbr)}] (LL) at (LeftRasterbox.south west);% Lower Left
\coordinate[shift={(-\hbr,\hbr)}] (LR) at (RightRasterbox.south east);% Lower Right
\coordinate[shift={(\hbr,-\hbr)}] (UL) at (LeftRasterbox.north west);% Upper Left
\coordinate[shift={(-\hbr,-\hbr)}] (UR) at (RightRasterbox.north east);% Upper Right
\coordinate[shift={(-\hbr,\hbr)}] (LLM) at (LeftRasterbox.south east);% Lower Left Middle
\coordinate[shift={(-\hbr,-\hbr)}] (ULM) at (LeftRasterbox.north east);% Upper Left Middle
\coordinate[shift={(\hbr,\hbr)}] (LRM) at ([xshift=0]RightRasterbox.south west);% Lower Right Middle
\coordinate[shift={(\hbr,-\hbr)}] (URM) at ([xshift=0]RightRasterbox.north west);% Upper Left Middle
% Image Ruler x
\xRuler{LL}{LLM}{below}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={yshift=25mm}] (LL) -- +(\w,0) node[Help, pos=0.65, below=2pt] {LeftWidth = \LeftWidth \
LL--LLM = w = \w \
No. x divisions w/u = \NoXdiv};
\end{pgfonlayer}\fi
\xRuler{LRM}{LR}{below}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={yshift=25mm}] (LRM) -- +(\w,0) node[Help, pos=0.65, below=2pt] {RightWidth = \RightWidth \
LRM--LR = w = \w \
No. x divisions w/u = \NoXdiv};
\end{pgfonlayer}\fi
\xRuler{UL}{ULM}{above}{4mm}{2mm}
\xRuler{URM}{UR}{above}{4mm}{2mm}
% Image Ruler y
\yRuler{LL}{UL}{left}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={xshift=5mm}] (LL) -- +(0,\h) node[Help, pos=0.85, right=2pt] {(Left) Image Height h= \h \ No. y divisions h/u= \NoYdiv};
\end{pgfonlayer}\fi
\yRuler{LR}{UR}{right}{4mm}{2mm}
% Image Ruler y BIS
\def\ifzero{1} % do show zero
\yRulerBis{LLM}{ULM}{right}{4mm}{2mm}
\yRulerBis{LRM}{URM}{left}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={xshift=5mm}] (LRM) -- +(0,\h) node[Help, pos=0.85, right=2pt] {(Right) Image Height h= \h \ No. y divisions h/u= \NoYdiv};
\end{pgfonlayer}\fi
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={yshift=5mm}] (LL) -- +(\u,0) node[Help, pos=1.05, anchor=west]{Unit-length set u= \u};
\node[draw=cyan, fill=cyan!22, text=cyan, anchor=west, line width=\HelpBoxRule, align=left, inner sep=\HelpBoxRule] at ([yshift=3*\u, xshift=10mm]LRM) {HelpBoxRule = \HelpBoxRule \ 0pt in result};
\foreach \Coord/\Anchor in {LL/{north east}, LR/{north west},
UL/{south east}, UR/{south west}, LLM/{south east}, ULM/{north east}, LRM/{south west}, URM/{north west}%
}
\draw[red, thick] (\Coord) circle(2pt) node[Help, opacity=0.5, anchor=\Anchor]{\Coord};
\end{pgfonlayer}\fi
\end{tikzpicture}
\newpage
}
\end{document}
Instead of doing calculations using a constant, you can also use \foreach with a list of pattern a/b,c/d,e/f—just do something like:
\foreach \leftelement/\rightelement in {a/b,c/d,e/f}
In first iteration \leftelement will be a, \rightelement will be b.
In second iteration \leftelement will be c, \rightelement will be d.
In third iteration \leftelement will be e, \rightelement will be f.
% arara: pdflatex
% arara: pdflatex
% arara: pdflatex
\documentclass[a4paper, landscape]{article}
\pagestyle{empty}
\usepackage[showframe=false,
margin=20mm,
]{geometry}
%\geometry{paperwidth=15cm, paperheight=30cm, margin=2mm}% optional
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfkeys{/tikz/savevalue/.code 2 args={\global\edef#1{#2}}}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\usepackage[most]{tcolorbox}
\tcbset{
NoGaps/.style={boxsep=0mm, left=0pt, right=0pt, top=0pt, bottom=0pt, before skip=0pt, after skip=0pt,},
%
CommonStyle/.style={sharp corners,
enhanced, % allows TikZ etc.
colback=white,
boxrule=0mm, % 0.5mm = default
colframe=white, %frame hidden,
},
%
RasterStyle/.style={
raster equal skip=\SeperationBetweenImages,
raster equal height=rows,
raster halign=center, raster valign=center,
},
}
\newcommand\NiceForEachLeftElement{}%
\newcommand\NiceForEachRightElement{}%
% WHY TWO DIFFERENT COMMANDS \UseImageLeft AND \UseImageRight
% WHICH DO EXACTLY THE SAME?
\newcommand\UseImageLeft[2]{%
% #1 preceding phrase "image-"
% #2 number of image
\IfFileExists{#1#2.jpg}%
{\includegraphics[scale=\ImageScale]{#1#2.jpg}}%
{\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}
\newcommand\UseImageRight[2]{%
% #1 preceding phrase "image-"
% #2 number of image
\IfFileExists{#1#2.jpg}%
{\includegraphics[scale=\ImageScale]{#1#2.jpg}}%
{\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}
% Input ============
\xdef\author{The Author}
\def\TopTitleLeft{Object-0001}
\def\TopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
\def\TopTitleRight{Picture 1 of 16}
\def\TopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
\def\BottomTitle{\textcopyright~\author}
\def\ImageScale{0.15}
%
% WHY TWO DIFFERENT COMMANDS \ImageLeft AND \ImageRight
% WHICH DO EXACTLY THE SAME?
%
\newcommand\ImageLeft[1]{\UseImageLeft{Image-}{#1}}
\newcommand\ImageRight[1]{\UseImageRight{Image-}{#1}}
\pgfmathsetlengthmacro{\u}{15.07425pt}% unitlength
%
\def\ShowHelps{0} % 1 'yes' 0 'no'
% Input ============
\ifnum\ShowHelps=1
\pagecolor{lightgray!22} % see page margins
\def\HelpBoxRule{5.7pt}
\def\HelpGap{0mm}
\tcbset{ShowHelps/.style={boxrule=\HelpBoxRule, colframe=#1},
ShowHelps/.default={black},
}
\pgfmathsetlengthmacro{\SeperationBetweenImages}{1.18cm}
\else
\def\HelpBoxRule{5.7pt}
\pgfmathsetlengthmacro{\SeperationBetweenImages}{1.18cm+\HelpBoxRule+\HelpBoxRule}
\def\HelpBoxRule{0mm}
\def\HelpGap{0mm}
\tcbset{ShowHelps/.style=,} \fi
\newcommand\TopTitle{%
\begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=\large\bfseries,
raster columns=100, % Trick: '100 percent'...
]
\tcbitem[raster multicolumn=23, halign=left] \TopTitleLeft
\tcbitem[raster multicolumn=54, halign=center] \TopTitleMiddle
\tcbitem[raster multicolumn=23, halign=right] \TopTitleRight
\end{tcbitemize}}
% Definition of Image Ruler x
\newcommand\xRuler[5]{
\path let \p1=($(#1)-(#2)$) in
\pgfextra{ \pgfmathsetlengthmacro{\RasterboxesWidth}{veclen(\x1,\y1)} }
[savevalue={\w}{\RasterboxesWidth}];
\pgfmathsetmacro\NoXdiv{\w/\u} % Number of x dividions
\draw[Ruler] (#1) coordinate(X) -- (#2);
\foreach \n in {0,1,...,\NoXdiv}{%%
\draw[Ruler] ([xshift=\n\u]X) -- +(0,#4) node[#3, inner sep=1pt]{\ifnum\n=1 \n,cm \else \n\fi};
}%%
\foreach \n in {0.1,0.2,...,\NoXdiv}{%%
\draw[] ([xshift=\n\u]X) -- +(0,#5);
}%%
}
% Definition of Image Ruler y
\def\ifzero{1} % show zero
\newcommand\yRuler[5]{
\path let \p1=($(#1)-(#2)$) in
\pgfextra{ \pgfmathsetlengthmacro{\RasterboxesHeight}{veclen(\x1,\y1)} }
[savevalue={\h}{\RasterboxesHeight}];
\pgfmathsetmacro\NoYdiv{\h/\u} % Number of y dividions
\draw[Ruler] (#1) coordinate(Y) -- (#2);
\foreach \n in {0,1,...,\NoYdiv}{%%
\draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0) node[#3, inner sep=1pt]{
\ifnum\n=0 \ifnum\ifzero=1 \n \fi%
\else%
\ifnum\n=1 \n,cm%
\else \n%
\fi\fi};
}%%
\foreach \n in {0.1,0.2,...,\NoYdiv}{%%
\draw[] ([yshift=\n\u]Y) -- +(#5,0);
}%%
}
% Definition of Image Ruler y BIS
\def\ifzero{1} % show zero
\newcommand\yRulerBis[5]{
\path let \p1=($(#1)-(#2)$) in
\pgfextra{ \pgfmathsetlengthmacro{\RasterboxesHeight}{veclen(\x1,\y1)} }
[savevalue={\h}{\RasterboxesHeight}];
\pgfmathsetmacro\NoYdiv{\h/\u} % Number of y dividions
\draw[Ruler] (#1) coordinate(Y) -- (#2);
\foreach \n in {0,1,...,\NoYdiv}{%%
\ifnum\n=1 \ifdim#4>0pt \draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0) node[#3, inner sep=1pt]{\n,cm};% 1cm (from left image): bar + text
\else
\draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0);\fi% 1cm (from right image): bar
\else
\ifdim#4>0pt \draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0) node[#3, inner sep=1pt, minimum width=2.15em]{\n};% all numbers lower than 10 (from left image), excluding 1: bar + text
\else
\draw[Ruler] ([yshift=\n\u]Y) -- +(#4,0);\fi;% all numbers (from right image), excluding 1: bar
\fi;
};
\foreach \n in {0.1,0.2,...,\NoYdiv}{%%
\draw[] ([yshift=\n*\u]Y) -- +(#5,0);
}%%
}
\begin{document}
% outside the loop the width of Image-7.jpg or example-image.jpg:
\pgfmathsetlengthmacro\LeftWidth{width("\noexpand\noexpand\noexpand\ImageLeft{7}")}%
%\show\LeftWidth
\pgfmathsetlengthmacro\RightWidth{width("\noexpand\noexpand\noexpand\ImageRight{7}")}%
%\show\LeftWidth
% inside the loop:
% Assuming pictures image-1.jpg, image-2.jpg, image-3.jpg,
% image-17.jpg, image-18.jpg, image-19.jpg
\foreach \NiceForEachLeftElement/\NiceForEachRightElement in {1/17,2/18,3/19}{%
\pgfmathsetlengthmacro\LeftWidth{width("\noexpand\noexpand\noexpand\ImageLeft{\NiceForEachLeftElement}")}%
\pgfmathsetlengthmacro\RightWidth{width("\noexpand\noexpand\noexpand\ImageRight{\NiceForEachRightElement}")}%
% \show\LeftWidth
% Page Box:
\begin{tcolorbox}[CommonStyle, ShowHelps=red,
NoGaps, % top=3mm,
valign=center, halign=center, % Box content to page center
height=\textheight,
%Top Title ==========================
title=\TopTitle,
finish={
\node[align=left, anchor=north west] at (title.south west){\TopTitleLeftBelow};
},
% Bottom Title ========================
space to upper,
lower separated=false
]
% Images:
\begin{tcbitemize}[CommonStyle, RasterStyle, NoGaps, ShowHelps=cyan,
raster columns=2, %boxsep=\HelpGap,
halign=center, valign=center,
raster left skip=-1mm, raster right skip=-1mm,% not needed
raster force size=false, %size=tight,
]
\tcbitem[remember as=LeftRasterbox, ShowHelps=pink,
width=\LeftWidth+\HelpBoxRule+\HelpBoxRule+\HelpGap+\HelpGap] \ImageLeft{\NiceForEachLeftElement}%
\tcbitem[remember as=RightRasterbox,
width=\RightWidth+\HelpBoxRule+\HelpBoxRule+\HelpGap+\HelpGap] \ImageRight{\NiceForEachRightElement}%
\end{tcbitemize}
\tcblower
\BottomTitle
\end{tcolorbox}
\begin{tikzpicture}[overlay,remember picture,
Ruler/.style={thick},
Help/.style={|-|, very thick, yellow!77!orange, fill, text=red, inner sep=0.5pt, align=left},
]
\pgfmathsetlengthmacro\hbr{(\HelpBoxRule+0*\HelpGap)}
\coordinate[shift={(\hbr,\hbr)}] (LL) at (LeftRasterbox.south west);% Lower Left
\coordinate[shift={(-\hbr,\hbr)}] (LR) at (RightRasterbox.south east);% Lower Right
\coordinate[shift={(\hbr,-\hbr)}] (UL) at (LeftRasterbox.north west);% Upper Left
\coordinate[shift={(-\hbr,-\hbr)}] (UR) at (RightRasterbox.north east);% Upper Right
\coordinate[shift={(-\hbr,\hbr)}] (LLM) at (LeftRasterbox.south east);% Lower Left Middle
\coordinate[shift={(-\hbr,-\hbr)}] (ULM) at (LeftRasterbox.north east);% Upper Left Middle
\coordinate[shift={(\hbr,\hbr)}] (LRM) at ([xshift=0]RightRasterbox.south west);% Lower Right Middle
\coordinate[shift={(\hbr,-\hbr)}] (URM) at ([xshift=0]RightRasterbox.north west);% Upper Left Middle
% Image Ruler x
\xRuler{LL}{LLM}{below}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={yshift=25mm}] (LL) -- +(\w,0) node[Help, pos=0.65, below=2pt] {LeftWidth = \LeftWidth \
LL--LLM = w = \w \
No. x divisions w/u = \NoXdiv};
\end{pgfonlayer}\fi
\xRuler{LRM}{LR}{below}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={yshift=25mm}] (LRM) -- +(\w,0) node[Help, pos=0.65, below=2pt] {RightWidth = \RightWidth \
LRM--LR = w = \w \
No. x divisions w/u = \NoXdiv};
\end{pgfonlayer}\fi
\xRuler{UL}{ULM}{above}{4mm}{2mm}
\xRuler{URM}{UR}{above}{4mm}{2mm}
% Image Ruler y
\yRuler{LL}{UL}{left}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={xshift=5mm}] (LL) -- +(0,\h) node[Help, pos=0.85, right=2pt] {(Left) Image Height h= \h \ No. y divisions h/u= \NoYdiv};
\end{pgfonlayer}\fi
\yRuler{LR}{UR}{right}{4mm}{2mm}
% Image Ruler y BIS
\def\ifzero{1} % do show zero
\yRulerBis{LLM}{ULM}{right}{4mm}{2mm}
\yRulerBis{LRM}{URM}{left}{-4mm}{-2mm}
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={xshift=5mm}] (LRM) -- +(0,\h) node[Help, pos=0.85, right=2pt] {(Right) Image Height h= \h \ No. y divisions h/u= \NoYdiv};
\end{pgfonlayer}\fi
\ifnum\ShowHelps=1
\begin{pgfonlayer}{foreground}
\draw[Help, transform canvas={yshift=5mm}] (LL) -- +(\u,0) node[Help, pos=1.05, anchor=west]{Unit-length set u= \u};
\node[draw=cyan, fill=cyan!22, text=cyan, anchor=west, line width=\HelpBoxRule, align=left, inner sep=\HelpBoxRule] at ([yshift=3*\u, xshift=10mm]LRM) {HelpBoxRule = \HelpBoxRule \ 0pt in result};
\foreach \Coord/\Anchor in {LL/{north east}, LR/{north west},
UL/{south east}, UR/{south west}, LLM/{south east}, ULM/{north east}, LRM/{south west}, URM/{north west}%
}
\draw[red, thick] (\Coord) circle(2pt) node[Help, opacity=0.5, anchor=\Anchor]{\Coord};
\end{pgfonlayer}\fi
\end{tikzpicture}
\newpage
}
\end{document}
\coordinate (foo) at (rel axis cs: 0.5,0.5);inside the axis environment. – John Kormylo Aug 31 '20 at 20:48