将 PDF 页面与网格叠加,网格左下角为 (0,0),右上角为 (10,10)

将 PDF 页面与网格叠加,网格左下角为 (0,0),右上角为 (10,10)

我想将 (0,0) 放在 PDF 页面的左下角,将 (10,10) 放在右上角。垂直和水平比例不一定相同。

给出了意外的输出,如下所示。

在此处输入图片描述

\documentclass{article}
\usepackage{mwe}
\usepackage{pdfpages}
\usepackage{tikz}


\begin{document}
\includepdf[pagecommand={%
\begin{tikzpicture}[remember picture,overlay]
  \begin{scope}[x={(current page.south east)},y={(current page.north west)}]
     \draw[help lines,xstep=0.1,ystep=0.1,red] (0,0) grid (1,1);
     \foreach \x in {0,1,...,10} {\node [anchor=north] at (\x/10,0) {\x}; }
     \foreach \y in {0,1,...,10} {\node [anchor=east] at (0,\y/10) {\y}; }
  \end{scope}
\end{tikzpicture}},pages=1,fitpaper=true]{example-image-a.pdf}
\end{document}

答案1

\documentclass{article}
\usepackage{mwe}
\usepackage{pdfpages}
\usepackage{tikz}


\begin{document}
\AddToHookNext{shipout/foreground}
{
  \put(0,-\pdfpageheight)
   {%
     \begin{tikzpicture}[remember picture,overlay]
      \begin{scope}[x={(current page.south east)},y={(current page.north west)}]
       \draw[help lines,xstep=0.1,ystep=0.1,red] (0,0) grid (1,1);
       \node at (0.5,0.5){xxxxx};
       \foreach \x in {0,1,...,10} {\node [anchor=south] at (\x/10,0) {\x}; }
       \foreach \y in {0,1,...,10} {\node [anchor=west] at (0,\y/10) {\y}; }
     \end{scope}
    \end{tikzpicture}
   }
   
}
\includepdf[pages=1,fitpaper=true]{example-image-a.pdf}
\end{document}

在此处输入图片描述

相关内容