自动标尺 - 如何在每张图片周围设置一组标尺,一页上并排显示两张图片

自动标尺 - 如何在每张图片周围设置一组标尺,一页上并排显示两张图片

考虑以下代码:

\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}
\newcommand\myvhcenter[1]
  {%
    \begingroup
      \sbox0{#1}%
      \raise.5\dimexpr\dp0-\ht0\relax\hbox to 0pt{\hss\usebox0\hss}%
    \endgroup
  }
\newcommand\myhcenter[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={\global\edef#1{#2}}}

\def\iPlusConstant{\the\numexpr\i+16}

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

\def\ShowHelps{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}

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

\newcommand\ExtraPictureOnEveryPage{
\AddToShipoutPictureBG{\AtPageCenter{
\myvhcenter{
\includegraphics[width=0.4\textwidth]{\NameOfExtraPictureOnEveryPage}
}
}}
}

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

\AddToShipoutPictureBG{\put(\LenToUnit{.5\paperwidth}, 0){
\myhcenter{
\begin{tcbitemize}[size=tight, halign=center, raster equal skip=0pt, raster width=\ScaleImagesAndRulers\textwidth, 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/\rulerpos\captiontext 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=\ScaleImagesAndRulers\textwidth, 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=\ScaleImagesAndRulers\textwidth, 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
\newcommand\ShowHelpCoSy{
  \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}; }
}
\ifnum\ShowHelps=1 \ShowHelpCoSy \fi%
\ifnum\ShowHelps=1\fill[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);
\ifnum\ShowHelps=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}];
\ifnum\ShowHelps=1 \node[Help] at (0.725,0.25) {unitlength U1U2 = \u}; \fi%<--- show unitlength
\ifnum\ShowHelps=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} 
\ifnum\n=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)}
      \ifnum\pgfmathresult=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)}
      \ifnum\pgfmathresult=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)}
      \ifnum\pgfmathresult=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)}
      \ifnum\pgfmathresult=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=1\textwidth, 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}

答案1

旧版本:

以下用途tcolorbox(广泛基于 TikZ)用于所有定位任务(这里不需要进一步的包)和TikZ标尺注释。

第一:单位长度 \u应该确定像这儿

该方法基于测量栅格框的尺寸,从而设置标尺的尺寸,例如

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

\pgfmathsetmacro\NoYdiv{\h/\u} % Number of y dividions

注意:如果没有共同x 标尺对于两幅图像,但对于两幅图像,有两个单独的方法,方法完全相同,只需要改变一些坐标。

注意:纸张颜色已设置为浅灰色以便看清边缘。


A。这是DIN A4页面2厘米边距;如果文档需要打印的话这可能很有用。 在此处输入图片描述

\def\ShowHelps{0}

在此处输入图片描述

B.如果它是纯电子文档,并且页面尺寸不重要(并且如果图像的 scale=1 是必需的),我们会在
\geometry{paperwidth=15cm, paperheight=30cm, margin=0mm}% optional

在此处输入图片描述

\def\ShowHelps{0}

在此处输入图片描述

% 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={\global\edef#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, 
},
}

%\def\ImageScale{0.1}
\newcommand\UseImage[1]{%
\IfFileExists{#1.jpg}%
  {\includegraphics[scale=\ImageScale]{#1.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.75}
\newcommand\ImageLeft{\UseImage{example-image}}
\newcommand\ImageRight{\UseImage{example-image-a}}
\pgfmathsetlengthmacro{\u}{51.07425pt}% unitlength
%
\def\ShowHelps{1} % 1 'yes'   0 'no'
% =======================================
% =======================================

\ifnum\ShowHelps=1 
\tcbset{ShowHelps/.style={boxrule=1mm, colframe=#1},
ShowHelps/.default={black},    
} \else
\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}}

\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}];

\pgfmathsetmacro\NoXdiv{\w/\u}  % Number of x dividions
\ifnum\ShowHelps=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

\newcommand\xRuler[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]{\ifnum\n=1 \n\,cm \else \n\fi};
}%%
\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}];

\pgfmathsetmacro\NoYdiv{\h/\u}  % Number of y dividions
\ifnum\ShowHelps=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

\newcommand\yRuler[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]{\ifnum\n=1 \n\,cm \else \n\fi};
}%%
\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}

\ifnum\ShowHelps=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}

新版本:

新 1.用空格水平擦除。
测量图像宽度,如

\pgfmathsetlengthmacro\LeftWidth{width("\ImageLeft")}

它可以用来

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

同时设置raster force size=falsetcbitemize 环境。

新 2。定制的 x 标尺。

添加一些坐标并将测量值放入 x-ruler-command 中

% Images 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, 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]{\ifnum\n=1 \n\,cm \else \n\fi};
}%%
\foreach \n in {0.1,0.2,...,\NoXdiv}{%% 
\draw[transform canvas={xshift=0mm}] ([xshift=\n*\u]X) -- +(0,#5);
}%%
}

允许例如\xRuler{LRM}{LR}{below}{-4mm}{-2mm}

在此处输入图片描述

附结果版本 \def\ShowHelps{0}

在此处输入图片描述

% 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={\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=0mm, 
raster equal height=rows, 
raster halign=center, raster valign=center, 
},
}

%\def\ImageScale{0.1}
\newcommand\UseImage[1]{%
\IfFileExists{#1.jpg}%
  {\includegraphics[scale=\ImageScale]{#1.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.75}
\def\ImageLeft{\UseImage{example-image}}
%\def\ImageScale{0.075}
%\def\ImageLeft{\UseImage{cmHgI}}
\def\ImageRight{\UseImage{example-image-a}}
\pgfmathsetlengthmacro{\u}{51.07425pt}% unitlength
%
\def\ShowHelps{1} % 1 'yes'   0 'no'
% =======================================
% =======================================

\pgfmathsetlengthmacro\LeftWidth{width("\ImageLeft")}
\pgfmathsetlengthmacro\RightWidth{width("\ImageRight")}

\ifnum\ShowHelps=1 
\pagecolor{lightgray!22} % see page margins
\def\HelpBoxRule{5.7pt}
\def\HelpGap{0pt}
\tcbset{ShowHelps/.style={boxrule=\HelpBoxRule, colframe=#1},
ShowHelps/.default={black},    
} \else
\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}}

\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},
]
\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


% Images 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);
}%%
}
%\xRuler{LL}{LR}{below}{-4mm}{-2mm}% old
\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}{UR}{above}{4mm}{2mm}
%\xRuler{URM}{UR}{above}{4mm}{2mm}

% 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);
}%%
}

\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}

\def\ifzero{0} % do not show zero
\yRuler{LLM}{ULM}{right}{4mm}{2mm}

\yRuler{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}
\end{document}

答案2

可能按照\number\numexpr...\relax对你有用的方式进行计算吗?

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


除了使用常量进行计算之外,您还可以使用\foreach模式列表a/b,c/d,e/f- 只需执行以下操作:

\foreach \leftelement/\rightelement in {a/b,c/d,e/f}

在第一次迭代中将\leftelementa\rightelement将是b
在第二次迭代\leftelement中将是c\rightelement将是d
在第三次迭代\leftelement中将是e\rightelement将是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}

答案3

改编自@cis 的答案:

代码1:

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

代码2:

对于高度相同的图像:两个单独的图像(它们之间的间距最小),中间的 y 标尺变成一个公共标尺,并使用共享的数字):

% 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\UseImageLeft[1]{%
\IfFileExists{#1.jpg}%
  {\includegraphics[scale=\ImageScale]{#1.jpg}}%
    {\includegraphics[scale=\ImageScale]{example-image.jpg}}%
}

\newcommand\UseImageRight[1]{%
\IfFileExists{#1.jpg}%
  {\includegraphics[scale=\ImageScale]{#1.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}
\def\ImageLeft{\UseImageLeft{example-image-a}}
\def\ImageRight{\UseImageRight{example-image-b}}
\pgfmathsetlengthmacro{\u}{15.07425pt}% unitlength
%
\def\ShowHelps{0} % 1 'yes'   0 'no'
% Input ============

\pgfmathsetlengthmacro\LeftWidth{width("\ImageLeft")}
\pgfmathsetlengthmacro\RightWidth{width("\ImageRight")}

\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}}

\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},
]
\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
    
% Images 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);
}%%
}

\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
\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);
}%%
}

% 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);
}%%
}

\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}

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

现在剩下的就是一个循环,以便可以加载多张图片,每页 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

使用Ulrich Diez 的回答此 OP 的:\pgfmathsetlengthmacro 与循环不兼容?,到目前为止:

代码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={\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{}%

\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}
\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:

\foreach \NiceForEachElement in {1,...,3}{%
  \pgfmathsetlengthmacro\LeftWidth{width("\noexpand\noexpand\noexpand\ImageLeft{\NiceForEachElement}")}%
  \pgfmathsetlengthmacro\RightWidth{width("\noexpand\noexpand\noexpand\ImageRight{\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{\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}

右侧图像仍然需要一些 i+16......

相关内容