3

I'm missing something, but the grid in my example doesn't want to cover the entire page area. There are unwanted margins on the top.

\documentclass[]{article}
\usepackage{tikz}
\usepackage[a4paper, landscape, margin=0pt, includeheadfoot]{geometry}

\begin{document}
\thispagestyle{empty}
\begin{center}
    \begin{tikzpicture}
        \draw[step=1.0,gray,thin] (current page.south west) grid (current page.north east);
    \end{tikzpicture}
\end{center}

\end{document}

enter image description here

12
  • 2
    Why are you using geometry in the first place. The whole point of standalone is that is adapts it self to the size of the contents. Thus adjust your tikzpicture to give it an actual size instead of trying to make it fit the document size as it is "undefined" in standalone (for a4paper: \draw[step=1.0,gray,thin] (0,0) grid (210mm,297mm);)
    – daleif
    Dec 28, 2022 at 10:24
  • 2
    as daleif said, you don't need geometry. all you need is \documentclass[tikz,a4paper,landscape]{standalone}
    – anis
    Dec 28, 2022 at 10:28
  • 1
    What are you trying to do?? standalone adapts the page size to the content, but your content tries to adapt to the page size, I'm getting dizzy trying to imagine what should be the outcome here. Dec 28, 2022 at 10:38
  • 3
    you're missing the overlay,remember picture options to the tikzpicture1`
    – daleif
    Dec 28, 2022 at 11:14
  • 2
    you could use the pagegrid package. Dec 28, 2022 at 11:22

1 Answer 1

4

Although the question isn't clear, you apparently are trying to draw a grid on the background of a page.

You can use either tikz package alone for a single page or combine it with background to get it in pages you want.

Single page

\documentclass[a4paper,margin=0pt]{article}
\usepackage{lipsum} % for the filling text
\usepackage{tikz}

\begin{document}
    
    \begin{tikzpicture}[remember picture,overlay]
    \draw[step=1.0,gray,thin] (current page.south west) grid (current page.north east);
    \end{tikzpicture}
\lipsum
\end{document}

Background

\documentclass[A4paper,margin=0pt]{article}
\usepackage{lipsum} % for the filling text

\usepackage{background}

\makeatletter
\def\bg@material{%
    \begin{tikzpicture}[remember picture,overlay]
        \draw[step=1.0,gray,thin] (current page.south west) grid (current page.north east);
            \end{tikzpicture}
}
\makeatother

\pagestyle{empty}

\begin{document}
\lipsum
\end{document}

the code was borrowed from position background image with \SetBgAnchor

Also, possible duplicate.

2
  • 1
    Thank you, as I realized from the comments, I just forgot overlay, remember picture and geometry package nothing to do with here. Dec 28, 2022 at 11:50
  • You can also use \AddToHookNext{shipout/background}{...}. Frankly, the background package is obsolete, although is still works. Dec 28, 2022 at 15:36

You must log in to answer this question.

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