pdflatex问题

pdflatex问题

我只是使用 latex 来网格化 pdf 文件。

代码如下

\documentclass[ letterpaper, 10pt]{article}
\usepackage{tikz}
\usepackage{pdfpages}

\newcommand\su[1]{
\begin{tikzpicture}[overlay,remember picture]%
\node at (current page.north west){
 \begin{tikzpicture}[remember picture, overlay]
    \draw[very thin, blue!10,step=0.2in]
  (current page.south west) grid (current page.north east);
  \draw[very thin, red!20,step=1in]
  (current page.south west) grid (current page.north east);
  \end{tikzpicture}
};
\end{tikzpicture}%
}
\begin{document}

\includepdf[pages=-,scale=1,pagecommand={\su}]{Jan31.pdf}
\end{document}

编译命令是

pdflatex xxx.pdf
xelatex  xxx.pdf

步骤1:pdflatex编译后,pdf文件没有显示任何网格。

在此处输入图片描述

步骤2:然后我尝试使用 xelatex 生成 pdf 文件,它只在底部显示一点网格。

在此处输入图片描述

步骤3:我尝试使用pdflatex再次生成它,文件被改变了,它显示了大部分网格,但缺少顶部的一些。

在此处输入图片描述

步骤4:再次使用pdflatex,只漏掉底部的1英寸。

在此处输入图片描述

步骤5:再次使用pdflatex……它起作用了!!!

在此处输入图片描述

之后我做了很多实验。

如果不运行xelatex,无论运行多少次pdflatex,pdf文件都无法网格化(就像步骤1的图片)。

但是如果运行一次xelatex,运行几次pdflatex,pdf文件就会变成网格状(就像步骤5的图片一样)

版本:

pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013)
kpathsea version 6.1.1
Copyright 2013 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.6.1; using libpng 1.6.1
Compiled with zlib 1.2.7; using zlib 1.2.7
Compiled with xpdf version 3.03

xelatex -v
XeTeX 3.1415926-2.5-0.9999.3-2013052718 (TeX Live 2013)
kpathsea version 6.1.1
Copyright 2013 SIL International and Jonathan Kew.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 51.1; using 51.1
Compiled with zlib version 1.2.7; using 1.2.7
Compiled with FreeType2 version 2.4.11; using 2.4.11
Compiled with Graphite2 version 1.2.1; using 1.2.1
Compiled with HarfBuzz version 0.9.15; using 0.9.15
Using Mac OS X Core Text, Cocoa & ImageIO frameworks

答案1

选项会记住文件中remember picture的位置,并使用记住的值tikzpicture.aux下一个LaTeX 运行。在更复杂的情况下(如嵌套 s 的问题tikzpicture),可能需要更多次运行。在您的例子中,需要运行三次:

pdflatex xxx
pdflatex xxx
pdflatex xxx

或者

xelatex xxx
xelatex xxx
xelatex xxx

不是混合 pdfTeX 和 XeTeX,因为内部位置值不兼容。

示例的复杂性可以降低,因此只需要运行两次:

\documentclass[letterpaper, 10pt]{article}
\usepackage{tikz}
\usepackage{pdfpages}

\newcommand\su{%
  \begin{tikzpicture}[
    overlay,
    remember picture,
    shift={(current page.north west)},
  ]
    \draw[very thin, blue!10, step=.2in]
      (current page.south west) grid (current page.north east);
    \draw[very thin, red!20,step=1in]
      (current page.south west) grid (current page.north east);
  \end{tikzpicture}%
}

\begin{document}
  \includepdf[pages=-,pagecommand={\su}]{Jan31.pdf}
\end{document}

答案2

为了进行更改,您可以使用background提供宏的包\BgThispage

\documentclass[ letterpaper, 10pt]{article}
\usepackage{pdfpages}
\usepackage[]{background}    %% this loads tikz

\backgroundsetup{
pages=some,
scale=1,
opacity=1,
angle=0,
color=black,
contents={%
 \begin{tikzpicture}[overlay,remember picture,shift={(current page.north west)}]
    \draw[very thin, blue!10,step=0.2in]
  (current page.south west) grid (current page.north east);
  \draw[very thin, red!20,step=1in]
  (current page.south west) grid (current page.north east);
  \end{tikzpicture}%
}
}
\begin{document}

\includepdf[pages=1-4,scale=1,pagecommand={\BgThispage}]{pgfmanual.pdf}
\end{document}

在此处输入图片描述

编译这个pdflatex,需要 2-3 次编译才能使事情稳定下来。

这是一个非常轻量级的解决方案,使用eso-pic

\documentclass[ letterpaper, 10pt]{article}
\usepackage[grid,gridunit=mm,gridcolor=red!20,subgridcolor=blue!10]{eso-pic}
\usepackage{pdfpages}
\gridSetup[mm]{1mm}{1}{5}{20}{1}

\begin{document}

\includepdf[pages=1-4,scale=1]{pgfmanual.pdf}
\end{document}

在此处输入图片描述

相关内容