4

I am trying to use TikZ to draw a rectangle inside an A4 piece of paper, with an exact 8mm margin around the rectangle. I found that in landscape mode, an A4 piece of paper has the dimensions 297 x 210 mm. So, I calculated that with an 8mm margin, my rectangle should be 281 x 194 mm.

When I wrote this into code, my output seems to have a larger margin on the left than on the right. Why is this the case?

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

\usepackage[margin=8mm]{geometry}
\usepackage{tikz}

% suppress page numbers
\pagenumbering{gobble}

\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (28.1,19.4);
\end{tikzpicture}
\end{document}

enter image description here

4
  • 8
    after {document} add \noindent
    – percusse
    Jul 27 '17 at 4:14
  • @percusse Why does that work and why is it necessary? Jul 27 '17 at 4:37
  • 2
    Because the default settings are that the first paragraph is indented (except after section headings). To TeX a tikzpicture is linke any other character: just a box that has to be positioned. See the behavior if you had test inctead of a picture. The begining of the paragraph will be indented. Jul 27 '17 at 6:08
  • @percusse Could you please submit your comment as answer, with a short explanation as to why it works and why it is necessary, and I will accept it? Jul 27 '17 at 9:11
4

As an alternative to percusse's solution you can use current page node to fix the desired rectangle. It uses remember picture then you need to compile twice before obtaining the correct result.

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

\usepackage[margin=8mm]{geometry}
\usepackage{tikz}

% suppress page numbers
\pagenumbering{gobble}

\begin{document}
\begin{tikzpicture}[overlay,remember picture]
\draw ([shift={(8mm,8mm)}]current page.south west) rectangle ([shift={(-8mm,-8mm)}]current page.north east);
\end{tikzpicture}
\end{document}

enter image description here

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.