如何添加与页面上的元素对齐的剪切标记?

如何添加与页面上的元素对齐的剪切标记?

我正在为我的学生设计一款记忆卡游戏,并设置了一个 6cm x 6cm 的卡片网格,如下所示:

在此处输入图片描述

问题是我不太会用这台切割机,总是会错过线条。所以我想在所有与网格线对齐的边框上添加切割标记。这样我就可以稍微切割一下,看看它是否在正确的位置。

网格生成如下所述:https://newbedev.com/foreach-loop-inside-the-tikz-picture-creation-of-memory-cards-using-tikz我只做了一点调整,所以在我看来它看起来是这样的:

%%% Global Setup
\newcommand\xspacing{86pt}%<== space between the images
\newcommand\yspacing{86pt}%<== vertical space between rows
\newcommand\imgperrow{4}%<== number of images per row

%%% Define primary for loop
\newcommand{\forloop}[2]{%
    \foreach [count=\i] \x in {#1,...,#2}%<==loop for each image in the array
    {
        \edef\gonode{\noexpand\node[inner sep=0pt] (B) at (A) {\noexpand\includegraphics[width=6cm]{\getimage{\x}}};}%<==Edit to expand the file name
        \gonode%
        \draw [black, ultra thick] ($(B.north west)$) rectangle ($(B.south east)$);%
        \pgfmathparse{Mod(\i,\imgperrow)==0?1:0};%
        \ifnum\pgfmathresult>0
        \coordinate (left) at ([yshift=-\yspacing]left);
        \path let \p1=(left),\p2=(B.south) in coordinate (A) at (\x1,\y2-\yspacing);
        \else   
        \coordinate (A) at ([xshift=\xspacing]B.east);%
        \fi
}}

\begin{document}
    \pagestyle{empty}
    %first page
    \begin{tikzpicture}[remember picture, overlay]
        \coordinate (A) at (page cs:-0.5045,0.595);
        \coordinate (left) at (A);
        \forloop{1}{24}
    \end{tikzpicture}

\end{document}

现在我有点迷茫,不知道是否可以访问网格线(实际上是矩形,正如您从代码中看到的那样)的坐标并在这些位置的边框上放置切割标记。

附录:这是完整的代码。我尝试删除不必要的部分。

\documentclass[12pt]{article}
% ############################## geometry
\usepackage{geometry}
\geometry{
    headsep = 0pt,
    headheight= 0pt, 
    hmarginratio =  1:1,
    vmarginratio = 1:1,
    bindingoffset = 0cm,
    onecolumn,
    a3paper,
    layoutwidth = 240 mm,
    layoutheight = 360 mm,
    layouthoffset=\dimexpr(\paperwidth-\csname Gm@layoutwidth\endcsname)/2\relax,
    layoutvoffset=\dimexpr(\paperheight-\csname Gm@layoutheight\endcsname)/2\relax,
    showcrop
}

\usepackage[utf8]{inputenc}


\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{mwe}


% ############################### Document

\newcommand{\czHyphen}{\rule[.45ex]{.2em}{.11ex}}
\newcommand*{\addthinS}{\hskip0.06667em\relax}
\newcommand*{\addthinSS}{\hskip0.00007em\relax}
\def\cropmarkgap{1}% mm

\makeatletter
\def\Gm@cropmark(#1,#2,#3,#4){% #1 = x direction, #2 = y direction, #3 & #4 no longet used
    \begin{picture}(0,0)
        \setlength\unitlength{1truemm}%
        \linethickness{0.25pt}%
        \put(\the\numexpr #1*\cropmarkgap\relax,0){\line(#1,0){\the\numexpr 20-\cropmarkgap}}%
        \put(0,\the\numexpr #2*\cropmarkgap\relax){\line(0,#2){\the\numexpr 20-\cropmarkgap}}%
\end{picture}}%
\makeatother

\makeatletter
\def\parsecomma#1,#2\endparsecomma{\def\page@x{#1}\def\page@y{#2}}
\tikzdeclarecoordinatesystem{page}{
    \parsecomma#1\endparsecomma
    \pgfpointanchor{current page}{north east}
    % Save the upper right corner
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    % save the lower left corner
    \pgfpointanchor{current page}{south west}
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    % Transform to the correct placement
    \pgfmathparse{(\pgf@xc-\pgf@xb)/2.*\page@x+(\pgf@xc+\pgf@xb)/2.}
    \expandafter\pgf@x\expandafter=\pgfmathresult pt
    \pgfmathparse{(\pgf@yc-\pgf@yb)/2.*\page@y+(\pgf@yc+\pgf@yb)/2.}
    \expandafter\pgf@y\expandafter=\pgfmathresult pt
}
\makeatother

\usepackage{eso-pic}
\usepackage{tikzpagenodes}
%\AddToShipoutPicture{\drawbackground}
\newcommand{\shiftleft}{\hspace*{-0.55\dimexpr\csname Gm@layoutwidth\endcsname-\textwidth\relax}}
\newcommand{\shiftup}{\vspace*{-0.13\dimexpr\csname Gm@layoutheight\endcsname-\textwidth\relax}}


%%% Define "Array" interface
\makeatletter
\newcounter{imgs}
\setcounter{imgs}{0}
%#1 is the image
\newcommand{\addimg}[1]{%
    \stepcounter{imgs}%
    \@namedef{imgimage\theimgs}{#1}%
}
\newcommand{\getimage}[1]{\expandafter\@nameuse\expandafter{imgimage#1}}%
\newcommand{\gettitle}[1]{\expandafter\@nameuse\expandafter{imgtitle#1}}%
\newcommand{\getcolor}[1]{\expandafter\@nameuse\expandafter{imgcolor#1}}%
\makeatother

%%% Define Cards
\addimg{tex-s2JJAi-1-two-points}
\addimg{tex-s2JJAi-1-point-and-shift}
\addimg{tex-s2JJAi-1-graph}
\addimg{tex-s2JJAi-1-point-and-slope}
\addimg{tex-s2JJAi-2-two-points}
\addimg{tex-s2JJAi-2-equation}
\addimg{tex-s2JJAi-2-graph}
\addimg{tex-s2JJAi-2-point-and-shift}
\addimg{tex-s2JJAi-3-point-and-shift}
\addimg{tex-s2JJAi-3-equation}
\addimg{tex-s2JJAi-3-two-points}
\addimg{tex-s2JJAi-3-point-and-slope}
\addimg{tex-s2JJAi-4-point-and-shift}
\addimg{tex-s2JJAi-4-two-points}
\addimg{tex-s2JJAi-4-point-and-slope}
\addimg{tex-s2JJAi-4-equation}
\addimg{tex-s2JJAi-5-two-points}
\addimg{tex-s2JJAi-5-point-and-shift}
\addimg{tex-s2JJAi-5-graph}
\addimg{tex-s2JJAi-5-equation}
\addimg{tex-s2JJAi-6-graph}
\addimg{tex-s2JJAi-6-point-and-slope}
\addimg{tex-s2JJAi-6-point-and-shift}
\addimg{tex-s2JJAi-6-equation}

%%% Global Setup
\newcommand\xspacing{86pt}%<== space between the images
\newcommand\yspacing{86pt}%<== vertical space between rows
\newcommand\imgperrow{4}%<== number of images per row}

%%% Define primary for loop
\newcommand{\forloop}[2]{%
    \foreach [count=\i] \x in {#1,...,#2}%<==loop for each image in the array
    {
        \edef\gonode{\noexpand\node[inner sep=0pt] (B) at (A) {\noexpand\includegraphics[width=6cm]{\getimage{\x}}};}%<==Edit to expand the file name
        \gonode%
        \draw [black, ultra thick] ($(B.north west)$) rectangle ($(B.south east)$);%
        \pgfmathparse{Mod(\i,\imgperrow)==0?1:0};%
        \ifnum\pgfmathresult>0
        \coordinate (left) at ([yshift=-\yspacing]left);
        \path let \p1=(left),\p2=(B.south) in coordinate (A) at (\x1,\y2-\yspacing);
        \else   
        \coordinate (A) at ([xshift=\xspacing]B.east);%
        \fi
}}

\begin{document}
    \pagestyle{empty}
    %page1
    \begin{tikzpicture}[remember picture, overlay]
        \coordinate (A) at (page cs:-0.61,0.715);
        \coordinate (left) at (A);
        \forloop{1}{24}
    \end{tikzpicture}

\end{document}

答案1

我感觉你的代码有点复杂。无论如何,我不会使用提供的裁剪标记,geometry而只是使用 Ti 绘制自定义的裁剪标记Z.下面的代码希望能够帮助您。

我删除了原始代码的大部分内容,因为我认为它们对于您的具体示例来说是不必要的。我定义了四个包含不同维度的新宏,即\shiftright\shiftdown和。\imgwidth\imgheight

我最终定义了一个新的宏\cropmarks,它接受两个参数,即列数和行数,并打印出每行和每列之间的裁剪标记。我希望这就是你想要的。

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}

% ############################## geometry
\usepackage{geometry}
\geometry{
    headsep = 0pt,
    headheight= 0pt, 
    hmarginratio =  1:1,
    vmarginratio = 1:1,
    bindingoffset = 0cm,
    onecolumn,
    a3paper,
    layoutwidth = 240mm,
    layoutheight = 360mm,
    layouthoffset=\dimexpr(\paperwidth-\csname Gm@layoutwidth\endcsname)/2\relax,
    layoutvoffset=\dimexpr(\paperheight-\csname Gm@layoutheight\endcsname)/2\relax,
}

\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}

% ############################### Document

\makeatletter
\newcommand{\shiftright}{\dimexpr\Gm@layouthoffset\relax}
\newcommand{\shiftdown}{\dimexpr\Gm@layoutvoffset\relax}
\makeatother

%%% Define "Array" interface
\makeatletter
\newcounter{imgs}
\setcounter{imgs}{0}
%#1 is the image
\newcommand{\addimg}[1]{%
    \stepcounter{imgs}%
    \@namedef{imgimage\theimgs}{#1}%
}
\newcommand{\getimage}[1]{\expandafter\@nameuse\expandafter{imgimage#1}}%
\makeatother

%%% Define Cards
\addimg{tex-s2JJAi-1-two-points}
\addimg{tex-s2JJAi-1-point-and-shift}
\addimg{tex-s2JJAi-1-graph}
\addimg{tex-s2JJAi-1-point-and-slope}
\addimg{tex-s2JJAi-2-two-points}
\addimg{tex-s2JJAi-2-equation}
\addimg{tex-s2JJAi-2-graph}
\addimg{tex-s2JJAi-2-point-and-shift}
\addimg{tex-s2JJAi-3-point-and-shift}
\addimg{tex-s2JJAi-3-equation}
\addimg{tex-s2JJAi-3-two-points}
\addimg{tex-s2JJAi-3-point-and-slope}
\addimg{tex-s2JJAi-4-point-and-shift}
\addimg{tex-s2JJAi-4-two-points}
\addimg{tex-s2JJAi-4-point-and-slope}
\addimg{tex-s2JJAi-4-equation}
\addimg{tex-s2JJAi-5-two-points}
\addimg{tex-s2JJAi-5-point-and-shift}
\addimg{tex-s2JJAi-5-graph}
\addimg{tex-s2JJAi-5-equation}
\addimg{tex-s2JJAi-6-graph}
\addimg{tex-s2JJAi-6-point-and-slope}
\addimg{tex-s2JJAi-6-point-and-shift}
\addimg{tex-s2JJAi-6-equation}

%%% Global Setup
\newcommand\imgwidth{6cm}   %<== width of images
\newcommand\imgheight{6cm}  %<== height of images
\newcommand\xspacing{0pt}   %<== space between the images
\newcommand\yspacing{0pt}   %<== vertical space between rows
\newcommand\imgperrow{4}    %<== number of images per row

%%% Define primary for loop
\newcommand{\forloop}[2]{%
    \foreach [count=\i] \x in {#1,...,#2}%<==loop for each image in the array
    {
        \edef\gonode{\noexpand\node[inner sep=0pt, outer sep=0pt, anchor=north west] (B) at (A) 
            %{\noexpand\includegraphics[width=\imgwidth, height=\imgheight]{example-image-a}};}  % just for testing purposes
            {\noexpand\includegraphics[width=\imgwidth, height=\imgheight]{\getimage{\x}}};} 
        \gonode%
        \draw [black, ultra thick] ($(B.north west)$) rectangle ($(B.south east)$);%
        
        \pgfmathparse{Mod(\i,\imgperrow)==0?1:0};%
        \ifnum\pgfmathresult>0
        
            \coordinate (left) at ([yshift=-\yspacing]left);
            \path let \p1=(left),\p2=(B.south) in coordinate (A) at (\x1,\y2-\yspacing);
            
        \else   
        
            \coordinate (A) at ([xshift=\xspacing]B.north east);%

        \fi
}}

\newcommand{\cropmarks}[2]{ % #1 = number of columns, #2 = number of rows
    \draw[thin] ([yshift={10pt}]A) -- ++(0,2);%

    \foreach [count=\i] \x in {0,...,#1} {
        \draw[thin] ([yshift={-\shiftdown+10pt}, xshift={\shiftright+(\i-1)*\imgwidth}]current page.north west) -- ++(0,2);
        \draw[thin] ([yshift={\shiftdown-10pt}, xshift={\shiftright+(\i-1)*\imgwidth}]current page.south west) -- ++(0,-2);
    }
    
    \foreach [count=\i] \x in {0,...,#2} {
        \draw[thin] ([xshift={\shiftright-10pt}, yshift={-\shiftdown-(\i-1)*\imgheight}]current page.north west) -- ++(-2,0);
        \draw[thin] ([xshift={-\shiftright+10pt}, yshift={-\shiftdown-(\i-1)*\imgheight}]current page.north east) -- ++(2,0);
    }
}

\begin{document}
    \pagestyle{empty}
    %page1
    \begin{tikzpicture}[remember picture, overlay]
        \coordinate (A) at ([xshift=\shiftright, yshift=-\shiftdown]current page.north west);
        \coordinate (left) at (A);
        \forloop{1}{24}
        
        \cropmarks{4}{6}
    \end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容