4

This question is related to my question Drawing a rectangle around a tikz node that fills up for example an a4-page, causes a page break — why?.

Mike's answer is fine, but if I use the parameters text width and text height (instead of minimum width and minimum height) the pagebreak occurs again, as you can see in this screenshot:

enter image description here

The following MWE is taken from Mike's answer. All I've modified, was replacing the minimum by text (and according percusse's comment) the \useboundingbox ... by overlay parameter, which is easier to read and does not seem to make a difference)

\documentclass{article}

\usepackage[%
paperheight=210mm,
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,
    text height=210mm,%<-- 'text' instead of minimum causes the break - why?
    text 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,overlay]
    (backFlap.north west) rectangle (backFlap.south east) {}%
    (backFlap.north east) -- (backFlap.south west) {}%
    (backFlap.north west) -- (backFlap.south east) {}%
    ;%
    \end{tikzpicture}%
\end{document}

My intention, switching to text height was: Currently (with minimum width and ... height) I use a minipage environment with fixed height and width inside the node to position textual content. Using text height and ... width option I thought to get rid of the extra minipage environment. Is this idea correct?

2 Answers 2

5

Torbjørn T.’s analysis is correct, but the workaround will misplace the text.

Since the issue is in the depth of the text in the lower left corner, make it having depth zero:

\node[
fill=green,
text height=210mm,
text width=297mm,
anchor=west,
inner sep=0pt,
outer sep=0pt]
(backFlap) at (p) {%
    \raisebox{\depth}{\huge Hello Worldy!}%
};

Full code

\documentclass{article}

\usepackage[
  paperheight=210mm,
  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,
    text height=210mm,
    text width=297mm,
    anchor=west,
    inner sep=0pt,
    outer sep=0pt]
    (backFlap) at (p) {%
        \raisebox{\depth}{\huge Hello Worldy!}%
    };%
    % setting bounding box to prevent enlargement of picture by line width
%   \useasboundingbox (0,-0.5\paperheight) rectangle (\paperwidth,0.5\paperheight);%
    \draw[thick,black,overlay]
    (backFlap.north west) rectangle (backFlap.south east) {}%
    (backFlap.north east) -- (backFlap.south west) {}%
    (backFlap.north west) -- (backFlap.south east) {}%
    ;%
    \end{tikzpicture}

\end{document}

Output

enter image description here

4
  • Thank you for your feedback. Does "Torbjørn T.’s analysis is correct" mean that you also don't get a pagebreak, after compilation of my MWE? (please see screenshot)
    – lAtExFaN
    Jun 15, 2017 at 13:14
  • @lAtExFaN The analysis is correct in the sense that if the text has a depth it will produce an overfull vbox, hence a page break. With \raisebox I get just one page.
    – egreg
    Jun 15, 2017 at 13:16
  • Another solution: don't use \raisebox and add the text depth=0 option to the green node... Jun 15, 2017 at 14:06
  • @PaulGaborit But then the descenders would by clipped.
    – egreg
    Jun 15, 2017 at 14:07
4

The example you provide only produces one page actually, but if you add a letter that has depth, for example a y, to the node, you do get a page break. The total height of the node is text height + text depth. With Hello world! the depth is zero, so the total height is text height + 0.

Use for example

text depth=30mm,
text height=180mm,

making sure that the two add up to 210mm.

8
  • "The example you provide only produces one page actually, ..." That's strange, I just verified the MWE and after compilation I get a page break (Win7-64, Texlive 2017, Texstudio). I added a screenshot - what tex distibution are you using?
    – lAtExFaN
    Jun 15, 2017 at 13:09
  • @lAtExFaN TeX Live 2016 (haven't updated yet) on Kubuntu. Jun 15, 2017 at 13:13
  • I try to understand the depth: If I just print out \huge H no pagebreak occurs - if I add the e (which should have depth zero, if I understand your answer right) a page break occurs ... that confuses me
    – lAtExFaN
    Jun 15, 2017 at 13:22
  • @lAtExFaN I don't know why that would happen, you could test the code at the bottom of this answer to see if the depth is non-zero or not. Jun 15, 2017 at 13:25
  • I just used your code to get the depth of "Hello World!". It has a depth of 0.39809pt could you please verify this value with your installation? Thanks!
    – lAtExFaN
    Jun 15, 2017 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.