Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Why doesn't this tikz picture fit on the first page of the document?

\documentclass{report}

\usepackage{tikz}  
\usepackage[showframe, centering, text={17cm, 25cm}]{geometry}

\begin{document}

\noindent  
\begin{tikzpicture}  
\draw (0cm,0cm) grid (17cm,25cm);  
\end{tikzpicture}  

\end{document}

When I compile the picture is pushed to the second page and the first is blank. If I increase the height of the page slightly (say to 25.01cm) it fits. How is LaTeX handling this situation? Is there anyway to get an exact fit?

share|improve this question

1 Answer 1

up vote 31 down vote accepted

Your rectangle has a width and a height of 17cm+\pgflinewidth respectively 25cm+\pgflinewidth. That means you have to modify your example es follows:

\documentclass{report}

\usepackage{tikz}  
\usepackage[showframe, centering, text={17cm, 25cm}]{geometry}
\usetikzlibrary{calc}
\begin{document}

\noindent  
\begin{tikzpicture}  
\draw (0cm,0cm) grid ($(17cm,25cm)-(\pgflinewidth,\pgflinewidth)$);  
\end{tikzpicture}  

Explanation

The two mandatory points of a rectangle drawn by TikZ are located in the middle of the line. The following example demonstrate it:

\documentclass{report}

\usepackage{tikz}  
\usepackage[centering, text={17cm, 25cm}]{geometry}
\usetikzlibrary{calc}
\begin{document}

\noindent  
\begin{tikzpicture}  
\draw[line width=10pt,red] (0cm,0cm) rectangle (5,5);
\fill (0cm,0cm) circle (2pt);
\fill (5cm,5cm) circle (2pt);
\end{tikzpicture}  

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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