0

in the following minimal example:

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

it renders the following:

enter image description here

and

enter image description here

... in the 1st PDF page, the whole thing is shifted down by a few mm

... and in the 2nd PDF page, the left tikzimage is shifted down by a few mm again, and then the right tikzimage is shifted down by a further few mm.

worth noting that these gaps are vertical-only, whatever is causing these gaps do not appear to have any horizontal effect.

what is causing these unexpected "gaps"? how to remove them?

bguiz
  • 115

1 Answers1

1

As explained here: https://tex.stackexchange.com/a/55420/231952, «what TikZ needs is to know the paper dimensions and apparently it uses \paperwidth and \paperheight». So you need to set also \paperwidth and \paperheight. I can not explain why TikZ create those gaps but you can remove them by using the current page nodes. In such a case you can do without geometry as well:

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

enter image description here

Ivan
  • 4,368
  • hmmm.. ok that appears to have worked for my images, but I got stuck trying to apply the same pattern to my lines, e.g.
    \draw[black, anchor=north west, inner sep=0, outer sep=0] at (current page.north west)
          (230mm, 0mm) --
          (230mm, -10mm) --
          (220mm, -10mm);
    ```
    yields
    ```
    ! Use of \@next doesn't match its definition.
    l.117 ...=north west, inner sep=0, outer sep=0] at
                                                       (current page.north west)
    ```
    
    – bguiz Mar 27 '21 at 14:41
  • is there a way to use a at (current page.north west) on a regular draw command without a node? – bguiz Mar 27 '21 at 14:42
  • figured out how to do ^ using /node --> /tikz --> /draw – bguiz Mar 28 '21 at 15:42