TransWikia.com

Automated ruler - how to have one set of rulers around each picture, 2 pictures side by side on a page

TeX - LaTeX Asked on March 6, 2021

Considering this code:

documentclass[a4paper, landscape]{article}
usepackage[margin=0cm, showframe=false]{geometry} 
geometry{paperwidth=15cm, paperheight=30cm}
usepackage{mwe} % Dummy images

usepackage{comment}

usepackage[skins]{tcolorbox}
tcbuselibrary{raster}

usepackage{eso-pic}
newcommandmyvhcenter[1]
  {%
    begingroup
      sbox0{#1}%
      raise.5dimexprdp0-ht0relaxhbox to 0pt{hssusebox0hss}%
    endgroup
  }
newcommandmyhcenter[1]{makebox[0pt][c]{#1}}
   
usepackage{tikz}
usepackage{tikzpagenodes} % current page text area.center
usetikzlibrary{calc} 
usetikzlibrary{decorations.pathreplacing} 
usetikzlibrary{decorations.markings}
pgfkeys{/tikz/savevalue/.code 2 args={globaledef#1{#2}}}

defiPlusConstant{thenumexpri+16}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

defShowHelps{0} %    1 'yes'        0   'no'

newcommand{PictureIndexStartsAt}{0}
newcommand{PictureIndexEndsAt}{16}

newcommand{ImagePadding}{0}
newcommand{ScaleImagesAndRulers}{0.7}

newcommand{UOneCoordinateX}{0.1}
newcommand{UOneCoordinateY}{0.054}
newcommand{UTwoCoordinateX}{0.1}
newcommand{UTwoCoordinateY}{0.255}

newcommand{GridSize}{0.01}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

newcommandExtraPictureOnEveryPage{
AddToShipoutPictureBG{AtPageCenter{
myvhcenter{
includegraphics[width=0.4textwidth]{NameOfExtraPictureOnEveryPage}
}
}}
}

AddToShipoutPictureBG{AtPageUpperLeft{
begin{tabular}{ l }
vspace{18em}\
large Weight: 65g\
large Volume: ?\
large Density: ?\
end{tabular}
}}

AddToShipoutPictureBG{put(LenToUnit{.5paperwidth}, 0){
myhcenter{
begin{tcbitemize}[size=tight, halign=center, raster equal skip=0pt, raster width=ScaleImagesAndRulerstextwidth, boxrule = 0pt, frame hidden, colframe=white, colback=white, colbacklower=white, 
raster left skip=-1mm, raster right skip=-1mm,% including this to solve horizontal alignment issues
]
tcbitem large Top-bottom rotation vspace{1.5em}\
tcbitem large Side rotation vspace{1.5em}\
end{tcbitemize}
}
}}

AddToShipoutPictureBG{AtPageLowerLeft{
begin{tabular}{ l }
vspace{-2.5em}\
© The Author \
end{tabular}
}}

begin{document}

foreach i in {PictureIndexStartsAt,...,PictureIndexEndsAt}{ %%%% Looping through these pictures
foreach image/rulerposcaptiontext in {
{./Pictures/Cropped-i}/{2,2}%%%%% Adjust the numbers if you want to have an extra ruler 
}{%%%%%%%%%%%%%%%

%centering
begin{tikzpicture}[
remember picture, overlay, % page center 1/3
shift={(current page.center)}, % page center 2/3
font=sffamily,
Help/.style={font=Huge, red}
]
node[anchor=center, %south west,
inner sep=ImagePadding pt] (myimage) at (0,0) {
IfFileExists{image.jpg}
  {
begin{tcbitemize}[size=tight, halign=center, raster equal skip=0pt, raster width=ScaleImagesAndRulerstextwidth, boxrule = 0pt, frame hidden, colframe=white, colback=white, colbacklower=white, 
raster left skip=1mm, raster right skip=-1mm]% including this to solve horizontal alignment issues
tcbitem includegraphics[width=textwidth]{./Pictures/Cropped-i.jpg}
tcbitem includegraphics[width=textwidth]{./Pictures/Cropped-iPlusConstant.jpg}
end{tcbitemize}  
  }
  {
begin{tcbitemize}[size=tight, halign=center, raster equal skip=0pt, raster width=ScaleImagesAndRulerstextwidth, boxrule = 0pt, frame hidden, colframe=white, colback=white, colbacklower=white, 
raster left skip=-1mm, raster right skip=-1mm]% including this to solve horizontal alignment issues
tcbitem includegraphics[width=textwidth]{example-image.jpg}
tcbitem includegraphics[width=textwidth]{example-image.jpg}
end{tcbitemize}  
  }
};
begin{scope}[x={($2*(myimage.east)$)},y={($2*(myimage.north)$)},
shift={(myimage.south west)} % page center 3/3
]
% Restrict the draw area
clip (-0.5,-0.5) rectangle (1.5,1.5);
% Frame around image -  optional
draw[] (0,0) rectangle (1,1); % optional
% CoSy inside node
newcommandShowHelpCoSy{
  draw[help lines,xstep=.1,ystep=GridSize] (0,0) grid (1,1);
  foreach x in {0,1,...,9} { node[anchor=north] at (x/10,0) {0.x}; }
  foreach y in {0,1,...,9} { node[anchor=east] at (0,y/10) {0.y}; }
}
ifnumShowHelps=1 ShowHelpCoSy fi%
ifnumShowHelps=1fill[Help] (0.5,0.75) circle(3pt) node[above]{(0.5,0.75)};fi% <-- Position Test

% Now the stuff:
path[] (UOneCoordinateX,UOneCoordinateY) coordinate(U1) -- (UTwoCoordinateX,UTwoCoordinateY) coordinate(U2);
ifnumShowHelps=1 draw[Help] (U1) circle(2pt) node[label=left:U1]{} -- (U2) circle(2pt) node[label=left:U2]{};fi % show unitlength line

path let p1=($(U2)-(U1)$) in 
pgfextra{  pgfmathsetlengthmacro{unitlength}{veclen(x1,y1)}   }
[savevalue={u}{unitlength},savevalue={mu}{.1*unitlength}];
ifnumShowHelps=1 node[Help] at (0.725,0.25) {unitlength U1U2 = u}; fi%<--- show unitlength
ifnumShowHelps=1 draw[blue, transform canvas={xshift=2mm}] (U1) -- +(0,u);fi  % Test

% Small Ruler
draw[very thick] (rulerpos) coordinate(A) -- +(0,3*u);
foreach n in {0,1,...,3}{%%
draw[very thick] ([yshift=n*u]A) -- +(-3mm,0) node[left]{n} 
ifnumn=0 node[anchor=west, right=3mm]{cm}fi;
}%%
foreach n in {0.1,0.2,...,3}{%% 
draw[] ([yshift=n*u]A) -- +(-1.5mm,0);
}%%

% Image Ruler y (left)
draw decorate [decoration=ticks,segment length=mu, /pgf/decoration/amplitude=0.5*mu]{ (-0.005,0) -- (-0.005,1) };
draw[thick] decorate [decoration=ticks,segment length=u, /pgf/decoration/amplitude=1*mu]{ (-0.01,0) -- (-0.01,1) };
begin{scope}[
  decoration={
    markings,
    mark=between positions 0 and 1 step u with {
      node [
        xshift=-2*mu,
        anchor=east,
        name=mark-pgfkeysvalueof{/pgf/decoration/mark info/sequence number}
      ]{
      pgfmathparse{int(pgfkeysvalueof{/pgf/decoration/mark info/sequence number}-1)}
      ifnumpgfmathresult=1
        1,cm
       else
        pgfmathresult
        fi
       };
    }
  }
]
draw [thick,postaction={decorate}] (0,0) -- (0,1);
end{scope}

% Image Ruler y (right)
draw decorate [decoration=ticks,segment length=mu, /pgf/decoration/amplitude=0.5*mu]{ (1.005,1) -- (1.005,0) };
draw[thick] decorate [decoration=ticks,segment length=u, /pgf/decoration/amplitude=1*mu]{ (1.01,1) -- (1.01,0) };
begin{scope}[
  decoration={
    markings,
    mark=between positions 0 and 1 step u with {
      node [
        xshift=2*mu,
        anchor=west,
        name=mark-pgfkeysvalueof{/pgf/decoration/mark info/sequence number}
      ]{
      pgfmathparse{int(pgfkeysvalueof{/pgf/decoration/mark info/sequence number}-1)}
      ifnumpgfmathresult=1
        1,cm
       else
        pgfmathresult
        fi
       };
    }
  }
]
draw [thick,postaction={decorate}] (1,1) -- (1,0);
end{scope}

% Image Ruler x (bottom)
draw decorate [decoration=ticks,segment length=mu, /pgf/decoration/amplitude=0.5*mu]{ (0,-0.01) -- (1,-0.01) };
draw[thick] decorate [decoration=ticks,segment length=u, /pgf/decoration/amplitude=1*mu]{ (0,-0.02) -- (1,-0.02) };
begin{scope}[
  decoration={
    markings,
    mark=between positions 0 and 1 step u with {
      node [
        yshift=-4*mu,
        anchor=south,
        name=mark-pgfkeysvalueof{/pgf/decoration/mark info/sequence number}
      ]{
      pgfmathparse{int(pgfkeysvalueof{/pgf/decoration/mark info/sequence number}-1)}
      ifnumpgfmathresult=1
        1,cm
       else
        pgfmathresult
        fi
       };
    }
  }
]
draw [thick,postaction={decorate}] (0,0) -- (1,0);
end{scope}

% Image Ruler x (top)
draw decorate [decoration=ticks,segment length=mu, /pgf/decoration/amplitude=0.5*mu]{ (1,1.01) -- (0,1.01) };
draw[thick] decorate [decoration=ticks,segment length=u, /pgf/decoration/amplitude=1*mu]{ (1,1.02) -- (0,1.02) };
begin{scope}[
  decoration={
    markings,
    mark=between positions 0 and 1 step u with {
      node [
        yshift=4*mu,
        anchor=north,
        name=mark-pgfkeysvalueof{/pgf/decoration/mark info/sequence number}
      ]{
      pgfmathparse{int(pgfkeysvalueof{/pgf/decoration/mark info/sequence number}-1)}
      ifnumpgfmathresult=1
        1,cm
       else
        pgfmathresult
        fi
       };
    }
  }
]
draw [thick,postaction={decorate}] (1,1) -- (0,1);
end{scope}

end{scope}
end{tikzpicture}
}
%vspace*{fill}

begin{tcbitemize}[raster columns=3, size=tight, halign=center, raster equal skip=0pt, raster width=1textwidth, boxrule = 0pt, frame hidden, colframe=white, colback=white, colbacklower=white, 
raster left skip=-1mm, raster right skip=-1mm,% including this to solve horizontal alignment issues
]
tcbitem large textbf{Object-00001}\
tcbitem large Found at: textbf{51.208 North, 4.383 East}\ Found in: textbf{August 2020}\
tcbitem large Picture i of PictureIndexEndsAt \
end{tcbitemize}

newpage
}%%%%%%%%%%%%%%%%%%%%%%%%

end{document}

3 Answers

Old version:

The following uses tcolorbox (which based widly on TikZ) for all positioning tasks (no further packages are required here) and TikZ for the ruler-annotations.

First: The unitlength u should be determined like here.

The method is based on to measure the dimensions of the raster boxes and thus to set the dimensions for the rulers, e.g.

% Image Ruler y
path let p1=($(LL)-(UL)$) in 
pgfextra{  pgfmathsetlengthmacro{RasterboxHeight}{veclen(x1,y1)}   }
[savevalue={h}{RasterboxHeight}];

pgfmathsetmacroNoYdiv{h/u} % Number of y dividions

Note: Should there not be a common x-ruler for both images, but two separate ones for the two images, the method is exactly the same, only some coordinates has to be changed.

Note: The paper color has been set lightly to gray to see the edges.


A. This is the case on a DIN A4 page with 2cm margins; which is probably useful if the document should be printable. enter image description here

With defShowHelps{0}

enter image description here

B. If it is a purely electronic document and page dimensions are unimportant (and if scale=1 is mandatory for the images), and we comment in
geometry{paperwidth=15cm, paperheight=30cm, margin=0mm}% optional

enter image description here

With defShowHelps{0}

enter image description here

% 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{mwe} % Dummy Images
usepackage{textcomp} % textcopyright

usepackage{tikz}
usetikzlibrary{calc} 
pgfkeys{/tikz/savevalue/.code 2 args={globaledef#1{#2}}}
%pagecolor{lightgray!22} % see page margins

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=0pt, 
raster equal height=rows, 
raster halign=center, raster valign=center, 
},
}

%defImageScale{0.1}
newcommandUseImage[1]{%
IfFileExists{#1.jpg}%
  {includegraphics[scale=ImageScale]{#1.jpg}}%
    {includegraphics[scale=ImageScale]{example-image.jpg}}%
}

% =======================================
% Input ===================================
xdefauthor{The Author}
defTopTitleLeft{Object-0001}
defTopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
defTopTitleRight{Picture 1 of 16}
defTopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
defBottomTitle{textcopyright~author}
defImageScale{0.75}
newcommandImageLeft{UseImage{example-image}}
newcommandImageRight{UseImage{example-image-a}}
pgfmathsetlengthmacro{u}{51.07425pt}% unitlength
%
defShowHelps{1} % 1 'yes'   0 'no'
% =======================================
% =======================================

ifnumShowHelps=1 
tcbset{ShowHelps/.style={boxrule=1mm, colframe=#1},
ShowHelps/.default={black},    
} else
tcbset{ShowHelps/.style=,}fi

newcommandTopTitle{%
begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=largebfseries,
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}}

begin{document}
% 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, 
halign=center, valign=center,
%colback=red,  
raster width=linewidth-2.4cm, % 1.2cm vspace for y Ruler left / right
%raster left skip=-1mm, raster right skip=-1mm,% not needed
]
tcbitem[remember as=LeftRasterbox] ImageLeft
tcbitem[remember as=RightRasterbox] ImageRight
end{tcbitemize} % remeber as=<name> for later TikZ-usage
tcblower
BottomTitle
end{tcolorbox}

begin{tikzpicture}[overlay,remember picture,
Ruler/.style={thick},
Help/.style={fill=yellow, text=red, inner sep=1pt},
]
coordinate[] (LL) at (LeftRasterbox.south west); % Lower Left
coordinate[] (LR) at (RightRasterbox.south east);% Lower Right
coordinate[] (UL) at (LeftRasterbox.north west); % Upper Left
coordinate[] (UR) at (RightRasterbox.north east);% Upper Right
%coordinate[label=x] (MR) at (LeftRasterbox.north east); % not used here

% Images Ruler x
path let p1=($(LL)-(LR)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesWidth}{veclen(x1,y1)} } 
[savevalue={w}{RasterboxesWidth}];

pgfmathsetmacroNoXdiv{w/u}  % Number of x dividions
ifnumShowHelps=1  node[Help, align=left, anchor=south east, yshift=3mm] at (LR.north west){Rasterboxes width w= w \ No. x divisions w/u= NoXdiv}; fi

newcommandxRuler[5]{
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]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoXdiv}{%% 
draw[] ([xshift=n*u]X) -- +(0,#5);
}%%
}
xRuler{LL}{LR}{below}{-4mm}{-2mm}
xRuler{UL}{UR}{above}{4mm}{2mm}


% Image Ruler y
path let p1=($(LL)-(UL)$) in 
pgfextra{  pgfmathsetlengthmacro{RasterboxHeight}{veclen(x1,y1)}   }
[savevalue={h}{RasterboxHeight}];

pgfmathsetmacroNoYdiv{h/u}  % Number of y dividions
ifnumShowHelps=1  node[Help, align=left, anchor=north west, xshift=3mm] at (UL.south east){Rasterbox height h= h \ No. y divisions h/u= NoYdiv}; fi

newcommandyRuler[5]{
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]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoYdiv}{%% 
draw[] ([yshift=n*u]Y) -- +(#5,0);
}%%
}
yRuler{LL}{UL}{left}{-4mm}{-2mm}
yRuler{LR}{UR}{right}{4mm}{2mm}

ifnumShowHelps=1 
node[Help, anchor=south west, yshift=3mm] at (LL.north east) {unitlength setted u= u};
foreach Coord/Pos in {LL/left,LR/right, UL/left,UR/right}
draw[red, thick] (Coord) circle(2pt) node[Help, opacity=0.5, Pos]{Coord};  fi
end{tikzpicture}
end{document}

New version:

New 1. Erasing horizontally withespaces.
With measuring out the image-widths like

pgfmathsetlengthmacroLeftWidth{width("ImageLeft")}

it can be used

tcbitem[remember as=LeftRasterbox, width=LeftWidth] ImageLeft

while setting raster force size=false for the tcbitemize-environment.

New 2. Customized x-rulers.

Adding some coordinates and putting in the measuring into the x-ruler-command

% Images Ruler x
newcommandxRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesWidth}{veclen(x1,y1)} } 
[savevalue={w}{RasterboxesWidth}];
pgfmathsetmacroNoXdiv{w/u}  % Number of x dividions

draw[Ruler, transform canvas={xshift=0mm}] (#1) coordinate(X) -- (#2);
foreach n in {0,1,...,NoXdiv}{%%
draw[Ruler] ([xshift=n*u]X) -- +(0,#4) node[#3, inner sep=1pt]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoXdiv}{%% 
draw[transform canvas={xshift=0mm}] ([xshift=n*u]X) -- +(0,#5);
}%%
}

allows e.g. xRuler{LRM}{LR}{below}{-4mm}{-2mm}

enter image description here

With result version defShowHelps{0}

enter image description here

% 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{mwe} % Dummy Images
usepackage{textcomp} % textcopyright

usepackage{tikz}
usetikzlibrary{calc} 
pgfkeys{/tikz/savevalue/.code 2 args={globaledef#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=0mm, 
raster equal height=rows, 
raster halign=center, raster valign=center, 
},
}

%defImageScale{0.1}
newcommandUseImage[1]{%
IfFileExists{#1.jpg}%
  {includegraphics[scale=ImageScale]{#1.jpg}}%
    {includegraphics[scale=ImageScale]{example-image.jpg}}%
}

% =======================================
% Input ===================================
xdefauthor{The Author}
defTopTitleLeft{Object-0001}
defTopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
defTopTitleRight{Picture 1 of 16}
defTopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
defBottomTitle{textcopyright~author}
defImageScale{0.75}
defImageLeft{UseImage{example-image}}
%defImageScale{0.075}
%defImageLeft{UseImage{cmHgI}}
defImageRight{UseImage{example-image-a}}
pgfmathsetlengthmacro{u}{51.07425pt}% unitlength
%
defShowHelps{1} % 1 'yes'   0 'no'
% =======================================
% =======================================

pgfmathsetlengthmacroLeftWidth{width("ImageLeft")}
pgfmathsetlengthmacroRightWidth{width("ImageRight")}

ifnumShowHelps=1 
pagecolor{lightgray!22} % see page margins
defHelpBoxRule{5.7pt}
defHelpGap{0pt}
tcbset{ShowHelps/.style={boxrule=HelpBoxRule, colframe=#1},
ShowHelps/.default={black},    
} else
defHelpBoxRule{0mm}
defHelpGap{0mm}
tcbset{ShowHelps/.style=,}fi

newcommandTopTitle{%
begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=largebfseries,
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}}

begin{document}
% 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,
%colback=red,  
%raster width=linewidth-2.4cm, % 1.2cm vspace for y Ruler left / right
%raster left skip=-1mm, raster right skip=-1mm,% not needed
raster force size=false, %size=tight,
%raster equal skip=HelpBoxRule, 
]
tcbitem[remember as=LeftRasterbox, ShowHelps=pink,
width=LeftWidth+HelpBoxRule+HelpBoxRule+HelpGap+HelpGap] ImageLeft
tcbitem[remember as=RightRasterbox, 
width=RightWidth+HelpBoxRule+HelpBoxRule+HelpGap+HelpGap] ImageRight
end{tcbitemize} % remeber as=<name> for later TikZ-usage
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},
]
pgfmathsetlengthmacrohbr{(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


% Images Ruler x
newcommandxRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesWidth}{veclen(x1,y1)} } 
[savevalue={w}{RasterboxesWidth}];
pgfmathsetmacroNoXdiv{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]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoXdiv}{%% 
draw[] ([xshift=n*u]X) -- +(0,#5);
}%%
}
%xRuler{LL}{LR}{below}{-4mm}{-2mm}% old
xRuler{LL}{LLM}{below}{-4mm}{-2mm}
ifnumShowHelps=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}
ifnumShowHelps=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}{UR}{above}{4mm}{2mm}
%xRuler{URM}{UR}{above}{4mm}{2mm}

% Image Ruler y
defifzero{1} % show zero
newcommandyRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{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]{
ifnumn=0 ifnumifzero=1 n fi%
    else%
        ifnumn=1 n,cm% 
           else n%
              fifi};
}%%
foreach n in {0.1,0.2,...,NoYdiv}{%% 
draw[] ([yshift=n*u]Y) -- +(#5,0);
}%%
}

yRuler{LL}{UL}{left}{-4mm}{-2mm}
ifnumShowHelps=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}

defifzero{0} % do not show zero
yRuler{LLM}{ULM}{right}{4mm}{2mm}

yRuler{LRM}{URM}{left}{-4mm}{-2mm}
ifnumShowHelps=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


ifnumShowHelps=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}
end{document}

Correct answer by cis on March 6, 2021

Probably doing calculation in terms of numbernumexpr...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={globaledef#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, 
},
}

newcommandNiceForEachElement{}%

% WHY TWO DIFFERENT COMMANDS UseImageLeft AND UseImageRight
% WHICH DO EXACTLY THE SAME?

newcommandUseImageLeft[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}}%
}

newcommandUseImageRight[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 ============
xdefauthor{The Author}
defTopTitleLeft{Object-0001}
defTopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
defTopTitleRight{Picture 1 of 16}
defTopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
defBottomTitle{textcopyright~author}
defImageScale{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
%
defShowHelps{0} % 1 'yes'   0 'no'
% Input ============

ifnumShowHelps=1 
pagecolor{lightgray!22} % see page margins
defHelpBoxRule{5.7pt}
defHelpGap{0mm}
tcbset{ShowHelps/.style={boxrule=HelpBoxRule, colframe=#1},
ShowHelps/.default={black},    
} 
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm}
else
defHelpBoxRule{5.7pt}
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm+HelpBoxRule+HelpBoxRule}
defHelpBoxRule{0mm}
defHelpGap{0mm}
tcbset{ShowHelps/.style=,} fi

newcommandTopTitle{%
begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=largebfseries,
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
newcommandxRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesWidth}{veclen(x1,y1)} } 
[savevalue={w}{RasterboxesWidth}];
pgfmathsetmacroNoXdiv{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]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoXdiv}{%% 
draw[] ([xshift=n*u]X) -- +(0,#5);
}%%
}

% Definition of Image Ruler y
defifzero{1} % show zero
newcommandyRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{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]{
ifnumn=0 ifnumifzero=1 n fi%
    else%
        ifnumn=1 n,cm% 
           else n%
              fifi};
}%%
foreach n in {0.1,0.2,...,NoYdiv}{%% 
draw[] ([yshift=n*u]Y) -- +(#5,0);
}%%
}

% Definition of Image Ruler y BIS
defifzero{1} % show zero
newcommandyRulerBis[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{h/u}  % Number of y dividions

draw[Ruler] (#1) coordinate(Y) -- (#2);
foreach n in {0,1,...,NoYdiv}{%%
ifnumn=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:
newcommandIndexDifference{16}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Adding IndexDifference to a given number:
newcommandAddIndexdifference[1]{%
  numbernumexpr(#1)+(IndexDifference)relax
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



begin{document}

% outside the loop the width of Image-7.jpg or example-image.jpg:

pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{7}")}%
%showLeftWidth

pgfmathsetlengthmacroRightWidth{width("noexpandnoexpandnoexpandImageRight{7}")}%
%showLeftWidth

pgfmathsetlengthmacroRightWidth{width("noexpandnoexpandnoexpandImageRight{AddIndexdifference{7}}")}%
%showLeftWidth


% inside the loop:

foreach NiceForEachElement in {1,...,3}{%
  pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{NiceForEachElement}")}%
  pgfmathsetlengthmacroRightWidth{width("noexpandnoexpandnoexpandImageRight{AddIndexdifference{NiceForEachElement}}")}%
%  showLeftWidth
 
  % 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},
]
pgfmathsetlengthmacrohbr{(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}
ifnumShowHelps=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}
ifnumShowHelps=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}
ifnumShowHelps=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

defifzero{1} % do show zero
yRulerBis{LLM}{ULM}{right}{4mm}{2mm}
yRulerBis{LRM}{URM}{left}{-4mm}{-2mm}
ifnumShowHelps=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

ifnumShowHelps=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={globaledef#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, 
},
}

newcommandNiceForEachLeftElement{}%
newcommandNiceForEachRightElement{}%

% WHY TWO DIFFERENT COMMANDS UseImageLeft AND UseImageRight
% WHICH DO EXACTLY THE SAME?

newcommandUseImageLeft[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}}%
}

newcommandUseImageRight[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 ============
xdefauthor{The Author}
defTopTitleLeft{Object-0001}
defTopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
defTopTitleRight{Picture 1 of 16}
defTopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
defBottomTitle{textcopyright~author}
defImageScale{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
%
defShowHelps{0} % 1 'yes'   0 'no'
% Input ============

ifnumShowHelps=1 
pagecolor{lightgray!22} % see page margins
defHelpBoxRule{5.7pt}
defHelpGap{0mm}
tcbset{ShowHelps/.style={boxrule=HelpBoxRule, colframe=#1},
ShowHelps/.default={black},    
} 
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm}
else
defHelpBoxRule{5.7pt}
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm+HelpBoxRule+HelpBoxRule}
defHelpBoxRule{0mm}
defHelpGap{0mm}
tcbset{ShowHelps/.style=,} fi

newcommandTopTitle{%
begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=largebfseries,
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
newcommandxRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesWidth}{veclen(x1,y1)} } 
[savevalue={w}{RasterboxesWidth}];
pgfmathsetmacroNoXdiv{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]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoXdiv}{%% 
draw[] ([xshift=n*u]X) -- +(0,#5);
}%%
}

% Definition of Image Ruler y
defifzero{1} % show zero
newcommandyRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{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]{
ifnumn=0 ifnumifzero=1 n fi%
    else%
        ifnumn=1 n,cm% 
           else n%
              fifi};
}%%
foreach n in {0.1,0.2,...,NoYdiv}{%% 
draw[] ([yshift=n*u]Y) -- +(#5,0);
}%%
}

% Definition of Image Ruler y BIS
defifzero{1} % show zero
newcommandyRulerBis[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{h/u}  % Number of y dividions

draw[Ruler] (#1) coordinate(Y) -- (#2);
foreach n in {0,1,...,NoYdiv}{%%
ifnumn=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:

pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{7}")}%
%showLeftWidth

pgfmathsetlengthmacroRightWidth{width("noexpandnoexpandnoexpandImageRight{7}")}%
%showLeftWidth

% 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}{%
  pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{NiceForEachLeftElement}")}%
  pgfmathsetlengthmacroRightWidth{width("noexpandnoexpandnoexpandImageRight{NiceForEachRightElement}")}%
%  showLeftWidth
 
  % 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},
]
pgfmathsetlengthmacrohbr{(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}
ifnumShowHelps=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}
ifnumShowHelps=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}
ifnumShowHelps=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

defifzero{1} % do show zero
yRulerBis{LLM}{ULM}{right}{4mm}{2mm}
yRulerBis{LRM}{URM}{left}{-4mm}{-2mm}
ifnumShowHelps=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

ifnumShowHelps=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}

Answered by Ulrich Diez on March 6, 2021

Adaptations of answer by @cis:

Code 1:

https://chat.stackexchange.com/transcript/message/55466772#55466772

Code 2:

For images of equal height: two seperate images (with minimal spacing between them), middle y-rulers into a common ruler, with shared numbers):

% 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={globaledef#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, 
},
}

newcommandUseImageLeft[1]{%
IfFileExists{#1.jpg}%
  {includegraphics[scale=ImageScale]{#1.jpg}}%
    {includegraphics[scale=ImageScale]{example-image.jpg}}%
}

newcommandUseImageRight[1]{%
IfFileExists{#1.jpg}%
  {includegraphics[scale=ImageScale]{#1.jpg}}%
    {includegraphics[scale=ImageScale]{example-image.jpg}}%
}

% Input ============
xdefauthor{The Author}
defTopTitleLeft{Object-0001}
defTopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
defTopTitleRight{Picture 1 of 16}
defTopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
defBottomTitle{textcopyright~author}
defImageScale{0.7}
defImageLeft{UseImageLeft{example-image-a}}
defImageRight{UseImageRight{example-image-b}}
pgfmathsetlengthmacro{u}{15.07425pt}% unitlength
%
defShowHelps{0} % 1 'yes'   0 'no'
% Input ============

pgfmathsetlengthmacroLeftWidth{width("ImageLeft")}
pgfmathsetlengthmacroRightWidth{width("ImageRight")}

ifnumShowHelps=1 
pagecolor{lightgray!22} % see page margins
defHelpBoxRule{5.7pt}
defHelpGap{0mm}
tcbset{ShowHelps/.style={boxrule=HelpBoxRule, colframe=#1},
ShowHelps/.default={black},    
} 
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm}
else
defHelpBoxRule{5.7pt}
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm+HelpBoxRule+HelpBoxRule}
defHelpBoxRule{0mm}
defHelpGap{0mm}
tcbset{ShowHelps/.style=,} fi

newcommandTopTitle{%
begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=largebfseries,
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}}

begin{document}

% 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
tcbitem[remember as=RightRasterbox, 
width=RightWidth+HelpBoxRule+HelpBoxRule+HelpGap+HelpGap] ImageRight
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},
]
pgfmathsetlengthmacrohbr{(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
    
% Images Ruler x
newcommandxRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesWidth}{veclen(x1,y1)} } 
[savevalue={w}{RasterboxesWidth}];
pgfmathsetmacroNoXdiv{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]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoXdiv}{%% 
draw[] ([xshift=n*u]X) -- +(0,#5);
}%%
}

xRuler{LL}{LLM}{below}{-4mm}{-2mm}
ifnumShowHelps=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}
ifnumShowHelps=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
defifzero{1} % show zero
newcommandyRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{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]{
ifnumn=0 ifnumifzero=1 n fi%
    else%
        ifnumn=1 n,cm% 
           else n%
              fifi};
}%%
foreach n in {0.1,0.2,...,NoYdiv}{%% 
draw[] ([yshift=n*u]Y) -- +(#5,0);
}%%
}

% Image Ruler y BIS
defifzero{1} % show zero
newcommandyRulerBis[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{h/u}  % Number of y dividions

draw[Ruler] (#1) coordinate(Y) -- (#2);
foreach n in {0,1,...,NoYdiv}{%%
ifnumn=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);
}%%
}

yRuler{LL}{UL}{left}{-4mm}{-2mm}
ifnumShowHelps=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}

defifzero{1} % do show zero
yRulerBis{LLM}{ULM}{right}{4mm}{2mm}
yRulerBis{LRM}{URM}{left}{-4mm}{-2mm}
ifnumShowHelps=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

ifnumShowHelps=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}
end{document}

What remains now is to have a loop, such that multiple images can be loaded, 2 per page.

Perhaps with

  • foreach i in {PictureIndexStartsAt,...,PictureIndexEndsAt}{
  • defiPlusConstant{thenumexpri+16}
  • LEFT includegraphics[width=textwidth]{./Pictures/XYZ-i.jpg}
  • RIGHT includegraphics[width=textwidth]{./Pictures/XYZ-iPlusConstant.jpg}
  • newpage

Using the answer of Ulrich Diez of this OP: pgfmathsetlengthmacro uncompatible with a loop?, got this far:

Code 3:

% 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={globaledef#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, 
},
}

newcommandNiceForEachElement{}%

newcommandUseImageLeft[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}}%
}

newcommandUseImageRight[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 ============
xdefauthor{The Author}
defTopTitleLeft{Object-0001}
defTopTitleMiddle{Found in August 2020 at 51.2 North, 49.1 East}
defTopTitleRight{Picture 1 of 16}
defTopTitleLeftBelow{Weight: 65g \ Volume: ? \ Density: ?}
defBottomTitle{textcopyright~author}
defImageScale{0.7}
newcommand*ImageLeft[1]{UseImageLeft{Image-}{#1}}
newcommand*ImageRight[1]{UseImageRight{Image-}{#1}}
pgfmathsetlengthmacro{u}{15.07425pt}% unitlength
%
defShowHelps{0} % 1 'yes'   0 'no'
% Input ============

ifnumShowHelps=1 
pagecolor{lightgray!22} % see page margins
defHelpBoxRule{5.7pt}
defHelpGap{0mm}
tcbset{ShowHelps/.style={boxrule=HelpBoxRule, colframe=#1},
ShowHelps/.default={black},    
} 
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm}
else
defHelpBoxRule{5.7pt}
pgfmathsetlengthmacro{SeperationBetweenImages}{1.18cm+HelpBoxRule+HelpBoxRule}
defHelpBoxRule{0mm}
defHelpGap{0mm}
tcbset{ShowHelps/.style=,} fi

newcommandTopTitle{%
begin{tcbitemize}[CommonStyle, RasterStyle, ShowHelps=brown,
NoGaps, boxsep=1mm,
fontupper=largebfseries,
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
newcommandxRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesWidth}{veclen(x1,y1)} } 
[savevalue={w}{RasterboxesWidth}];
pgfmathsetmacroNoXdiv{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]{ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoXdiv}{%% 
draw[] ([xshift=n*u]X) -- +(0,#5);
}%%
}

% Definition of Image Ruler y
defifzero{1} % show zero
newcommandyRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{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]{
ifnumn=0 ifnumifzero=1 n fi%
    else%
        ifnumn=1 n,cm% 
           else n%
              fifi};
}%%
foreach n in {0.1,0.2,...,NoYdiv}{%% 
draw[] ([yshift=n*u]Y) -- +(#5,0);
}%%
}

% Definition of Image Ruler y BIS
defifzero{1} % show zero
newcommandyRulerBis[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{h/u}  % Number of y dividions

draw[Ruler] (#1) coordinate(Y) -- (#2);
foreach n in {0,1,...,NoYdiv}{%%
ifnumn=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:

pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{7}")}%
%showLeftWidth

pgfmathsetlengthmacroRightWidth{width("noexpandnoexpandnoexpandImageRight{7}")}%
%showLeftWidth

% inside the loop:

foreach NiceForEachElement in {1,...,3}{%
  pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{NiceForEachElement}")}%
  pgfmathsetlengthmacroRightWidth{width("noexpandnoexpandnoexpandImageRight{NiceForEachElement}")}%
%  showLeftWidth
 
  % 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{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},
]
pgfmathsetlengthmacrohbr{(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}
ifnumShowHelps=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}
ifnumShowHelps=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}
ifnumShowHelps=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

defifzero{1} % do show zero
yRulerBis{LLM}{ULM}{right}{4mm}{2mm}
yRulerBis{LRM}{URM}{left}{-4mm}{-2mm}
ifnumShowHelps=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

ifnumShowHelps=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}

Still needs some i+16 for image on right...

Answered by O0123 on March 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP