使用 tikzpicture 时出现意外的垂直间隙

使用 tikzpicture 时出现意外的垂直间隙

在以下最小示例中:

\documentclass{article}
\usepackage{xcolor}
\usepackage[margin=0mm, noheadfoot]{geometry}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary {calc}
\usepackage[no-math]{fontspec}

\setmainfont{FreeSerif}
\setsansfont{FreeSans}
\setmonofont{FreeMono}

\usetikzlibrary{calc}
\parindent=0mm

\begin{document}

\eject
\pdfpagewidth=320mm
\pdfpageheight=220mm

% page#cover
\setcounter{page}{0}
\begin{tikzpicture}[remember picture, overlay]

    \draw node[anchor=north west, inner sep=0] at (10mm, -10mm) {
      \includegraphics[width=300mm, height=200mm]{example-image}
    };
    \draw[anchor=north west, black]
      (10mm, 0mm) --
      (10mm, -10mm) --
      (0mm, -10mm);
    \draw[anchor=north west, black]
      (310mm, -220mm) --
      (310mm, -210mm) --
      (320mm, -210mm);

  \fontsize{64}{76}\selectfont
  \draw node[anchor=north west] at (155mm, -20mm) {
    \hyphenpenalty 10000
    \exhyphenpenalty 10000
    \begin{minipage}{160mm}
      \rightskip=0pt plus .2\hsize
      \centering
      \textcolor{blue}{
        Title title
      }
    \end{minipage}
  };

\end{tikzpicture}

\eject
\pdfpagewidth=440mm
\pdfpageheight=220mm

% page#1
\setcounter{page}{1}
\begin{tikzpicture}[remember picture, overlay]

    \draw node[anchor=north west, inner sep=0] at (10mm, -10mm) {
      \includegraphics[width=200mm, height=200mm]{example-image}
    };
    \draw[anchor=north west, black]
      (10mm, 0mm) --
      (10mm, -10mm) --
      (0mm, -10mm);
    \draw[anchor=north west, black]
      (210mm, -220mm) --
      (210mm, -210mm) --
      (220mm, -210mm);

  \fontsize{18}{21}\selectfont
  \draw node[anchor=north west] at (30mm, -30mm) {
    \hyphenpenalty 10000
    \exhyphenpenalty 10000
    \begin{minipage}{\textwidth}
      \rightskip=0pt plus .2\hsize
      \textcolor{red}{
        some example text
      }
    \end{minipage}
  };

  \fontsize{18}{21}\selectfont
  \draw node[anchor=north west] at (15mm, -195mm) {
    \hyphenpenalty 10000
    \exhyphenpenalty 10000
    \begin{minipage}{\textwidth}
      \rightskip=0pt plus .2\hsize
      3
    \end{minipage}
  };

\end{tikzpicture}

% page#2
\setcounter{page}{2}
\begin{tikzpicture}[remember picture, overlay]

    \draw node[anchor=north west, inner sep=0] at (230mm, -10mm) {
      \includegraphics[width=200mm, height=200mm]{example-image}
    };
    \draw[black]
      (230mm, 0mm) --
      (230mm, -10mm) --
      (220mm, -10mm);
    \draw[black]
      (430mm, -220mm) --
      (430mm, -210mm) --
      (440mm, -210mm);

  \fontsize{18}{21}\selectfont
  \draw node[anchor=north west] at (230mm, -30mm) {
    \hyphenpenalty 10000
    \exhyphenpenalty 10000
    \begin{minipage}{160mm}
      \rightskip=0pt plus .2\hsize
      \textcolor{purple}{
        some example text
      }
    \end{minipage}
  };

  \fontsize{18}{21}\selectfont
  \draw node[anchor=north west] at (420mm, -195mm) {
    \hyphenpenalty 10000
    \exhyphenpenalty 10000
    \begin{minipage}{\textwidth}
      \rightskip=0pt plus .2\hsize
      4
    \end{minipage}
  };

\end{tikzpicture}

\end{document}

它呈现以下内容:

在此处输入图片描述

在此处输入图片描述

...在第一个 PDF 页中,整个内容向下移动了几毫米

...并且在第二个 PDF 页面中,左边tikzimage再次向下移动几毫米,然后右边又tikzimage向下移动几毫米。

值得注意的是,这些间隙仅仅是垂直的,无论是什么原因造成了这些间隙,似乎都不会产生任何水平影响。

是什么导致了这些意外的“差距”?如何消除它们?

答案1

如此处所述:https://tex.stackexchange.com/a/55420/231952,“TikZ需要知道纸张尺寸,显然它使用\paperwidth\paperheight”。因此,您还需要设置\paperwidth\paperheight。我无法解释为什么TikZ会产生这些间隙,但您可以使用current page节点将其移除。在这种情况下,您geometry也可以不用:

\documentclass{article}
\usepackage{xcolor}
%\usepackage[margin=0mm, noheadfoot]{geometry}
\usepackage{tikz}

\begin{document}

\eject
\pdfpagewidth=320mm
\pdfpageheight=220mm
\paperwidth=320mm
\paperheight=220mm

\begin{tikzpicture}[remember picture, overlay]
 \draw node[anchor=north west, inner sep=0,xshift=10mm,yshift=-10mm] at (current page.north west) {%
  \includegraphics[width=300mm, height=200mm]{example-image}};
\end{tikzpicture}

\eject
\pdfpagewidth=440mm
\pdfpageheight=220mm
\paperwidth=440mm
\paperheight=220mm

\begin{tikzpicture}[remember picture, overlay]
 \draw node[anchor=north west, inner sep=0,xshift=10mm,yshift=-10mm] at (current page.north west) {
  \includegraphics[width=200mm, height=200mm]{example-image}};
\end{tikzpicture}

\begin{tikzpicture}[remember picture, overlay]
 \draw node[anchor=north east, inner sep=0,xshift=-10mm,yshift=-10mm] at (current page.north east) {%
  \includegraphics[width=200mm, height=200mm]{example-image}};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容