2

The following tikz node fills up a whole a4 page. The page gets cropped afterwards using the crop-package (just for demonstration purposes, commenting the package out, doesn't seem to change anything). As long as I don't draw a rectangle around the node or a diagonal line for example everything is fine.

Drawing for example a diagonal line (see the screenshot and the comment in the following MWE) a page break occurs. My - ugly - workaround: I slightly (.281) increase the paper's height.

enter image description here

My question[s]: What exactly causes the page break? Do you know a better workaround?

\RequirePackage{luatex85}
\documentclass{article}

\usepackage[%
    paperheight=210mm,
%    paperheight=210.2812mm,%increasing the height seems to work, but ugly
    paperwidth=297mm,
    margin=0cm,
]{geometry}

\usepackage[cam,a3,landscape,center]{crop}
\usepackage[main=english]{babel}
\usepackage{tikz}

\setlength{\parindent}{0pt}

\begin{document}
\pagestyle{empty}%
\begin{tikzpicture}%
    \coordinate (p);%
    \node[%
        fill=green,
        minimum height=210mm,
        minimum width=297mm,
        anchor=west,
        inner sep=0pt,
        outer sep=0pt]%
        (backFlap) at (p) {%
            \huge Hello World!%
        };%
    %uncommenting any of these drawings causes a pagebreak -- why?
%    \draw[thick,black]
%        (backFlap.north west) rectangle (backFlap.south east) {}%
%        (backFlap.north east) -- (backFlap.south west) {}%
%        (backFlap.north west) -- (backFlap.south east) {}%
%    ;%
    \end{tikzpicture}%
\end{document}
lAtExFaN
  • 1,131

1 Answers1

3

Christan Hupfer is right, your problem is the line width. A line extends 0.5 times the line width to both sides of the path. In your case this will increase the size of your picture by the line width in both directions (x and y).

But you can set a bounding box in Tikz, which basically sets the size of the picture. Things outside of this box are not taken into account. See Tikz manual 15.8 Esatblishing a bounding box (page 175, manual for version 3.0.1a.

\documentclass{article}

\usepackage[%
    paperheight=210mm,
%    paperheight=210.2812mm,%increasing the height seems to work, but ugly
    paperwidth=297mm,
    margin=0cm,
]{geometry}

\usepackage[cam,a3,landscape,center]{crop}
\usepackage[main=english]{babel}
\usepackage{tikz}

\setlength{\parindent}{0pt}

\begin{document}
\pagestyle{empty}%
\begin{tikzpicture}%
    \coordinate (p);%
    \node[%
        fill=green,
        minimum height=210mm,
        minimum width=297mm,
        anchor=west,
        inner sep=0pt,
        outer sep=0pt]%
        (backFlap) at (p) {%
            \huge Hello World!%
        };%
    % setting bounding box to prevent enlargement of picture by line width
    \useasboundingbox (0,-0.5\paperheight) rectangle (\paperwidth,0.5\paperheight);%
    \draw[thick,black]
        (backFlap.north west) rectangle (backFlap.south east) {}%
        (backFlap.north east) -- (backFlap.south west) {}%
        (backFlap.north west) -- (backFlap.south east) {}%
    ;%
    \end{tikzpicture}%
\end{document}
Mike
  • 8,664
  • could you please explain, the factors? Why -0.5 and 0.5? -0.1 and 0.1 are working fine, too. – lAtExFaN May 20 '17 at 17:26
  • instead you can just add overlay option to the last command so it doesn't change the bounding box – percusse May 20 '17 at 17:48
  • @percusse: thanks I think, this is worth an answer, too. – lAtExFaN May 20 '17 at 18:05
  • @lAtExFaN \useasboundingbox only limits the bounding box of subsequent paths. Therefore even \useasboundingbox (0,0); (just a point) would work at this place, but not at the beginning of the tikzpicture. The bounding box given would, because it covers the node. I tend to use the final size of a picture, if I set the bounding box, in order to avoid later confusion. – Mike May 21 '17 at 13:57
  • @Mike if I use text width and text height (instead of minimum width and minimum height) the page breaks again. As I don't know where the space comes from I also don't how to remove it. Do you have an idea for a solution? Should I open up a new question? – lAtExFaN Jun 15 '17 at 10:43
  • I just posted a new question: https://tex.stackexchange.com/q/375097/112503 – lAtExFaN Jun 15 '17 at 12:47