4

I have the following test document:

\documentclass[11pt,a4paper,landscape]{article}

\usepackage[
    left=0.500cm,
    right=0.500cm,
    top=1.00cm,
    bottom=0.800cm,
]{geometry} % turning on showframe here makes
            % the thing even more puzzling (to me)
\usepackage{tikz}

\begin{document}
    
    \thispagestyle{empty}
    \begin{tikzpicture}
        \draw (0,0) rectangle (1,1);
        \draw (2,2) rectangle (3,3);
        \draw (4,4) rectangle (5,5);
        \draw (0,0) rectangle (27.9,20);
    \end{tikzpicture}

\end{document}

The first thing I don't know, and I didn't find any clue in the documentation to geometry, is if the margins (top, bottom, left, right) relate to the rotated page (because of landscape) or to the original page.

Whatever the case may be, I tried both: subtracting 1cm from the height of the landscape page and from the width. It does make a difference, but I still can't get what I would like: a rectangle that's exactly 0.5cm from the top and the bottom and exactly 1cm and 0.8cm from the right and left respectively. The current one (27.9 and 20; I tried other values) just goes to the very bottom of the page and doesn't stop at 0.5cm from the paper edge.

Sure enough I could do it with the page anchors of TikZ, but then I wouldn't know exactly how big they are and how they relate to the margins of geometry, which would be nice to know.

3
  • Have a look at the tikzpagenodes package Sep 5, 2022 at 9:52
  • 2
    Aren't you missing \noindent? The indentation is 15pt which is about 1/2 cm
    – Celdor
    Sep 5, 2022 at 10:19
  • @Celdor That works great indeed, thanks. You may make it an answer, if you wish.
    – Andyc
    Sep 5, 2022 at 10:32

2 Answers 2

4

I think the first thing you missed is \noindent which shifts the whole tikz picture rightwards by 15pt, that is ~ 0.5cm.

There are other extra gaps such as \topskip added before the first line and lineskip. After adding \vspace*{-\topskip} and \nointerlineskip, it seems the tikz picture is now in place

enter image description here

\documentclass[11pt]{article}

\usepackage[
    left=0.5cm,
    right=0.5cm,
    top=1cm,
    bottom=0.8cm,
    a4paper,
    landscape,
]{geometry} % turning on showframe here makes
            % the thing even more puzzling (to me)
\usepackage{tikz}

\thispagestyle{empty}

\begin{document}
\nointerlineskip\noindent%
\vspace*{-\topskip}%
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1);
    \draw (2,2) rectangle (3,3);
    \draw (4,4) rectangle (5,5);
    \draw (0,0) rectangle (28.7,19.2);
\end{tikzpicture}
\end{document}
5
  • The \noindent alone (per your comment) put the picture in place, but it left the first page blank. With the rest of your code, the picture is in the first page, where it should be. Mysteries of LaTeX...
    – Andyc
    Sep 5, 2022 at 10:37
  • 1
    Those guarantee that whatever LaTeX typesets will be readable (ish). There's still Overfull of ~0.4pt which is the length of a rule. If you subtract it from the horizontal dimension, that is 28.7cm-0.4pt, you will get the perfect box.
    – Celdor
    Sep 5, 2022 at 10:44
  • 1
    The 0.4pt overfull hbox comes up very often on this site, see Q58292 and its linked questions (the line width contributes to the bounding box). I'd suggest adding [trim left=0, trim right=28.7] to the tikzpicture, the lines drawn by TikZ will lie directly on the border then. Sep 5, 2022 at 13:26
  • @Qrrbrbirlbel Thanks. I thought it was caused by the right rule.
    – Celdor
    Sep 5, 2022 at 13:45
  • @Qrrbrbirlbel Although I'm not too concerned about an overfull box by 0.4pt, the linked question was an interesting reading indeed.
    – Andyc
    Sep 5, 2022 at 18:36
1

If (as I suspect) you are just trying to draw a single drawing on a single page, and not trying to make this part of a larger document, then you can do this much more simply with the standalone class:

\documentclass[tikz, border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1);
    \draw (2,2) rectangle (3,3);
    \draw (4,4) rectangle (5,5);
    \draw (0,0) rectangle (28.7,19.2);
\end{tikzpicture}
\end{document}

which you can compile to produce:

enter image description here

If you just want it to be A4 with arbitrary content, then try something like this (no margins, but an invisible A4 box).

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1);
    \draw (2,2) rectangle (3,3);
    \draw (4,4) rectangle (5,5);
    \draw[draw=none] (0,0) rectangle (29.7,21);
\end{tikzpicture}
\end{document}
2
  • Your suspect is almost right. I do print it out as a single picture, but I want it to fit exactly in a A4 page with the margins I want. Keep in mind that that was just a MWE to illustrate the problem I was having. The end product will be much more complicated than that (and I have another problem there, which will be the subject of another question, whenever I get to it).
    – Andyc
    Sep 5, 2022 at 13:26
  • 1
    Sure. Then you could remove the margins and draw an invisible A4 rectangle to get what you want. Answer updated.
    – Thruston
    Sep 5, 2022 at 13:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .