3

I used this answer to add gridlines to a pdf. Unlike in that question, I need the gridlines to go all the way to the edges of the page. The code below achieves that goal, with the second line below uncommented (and 3rd line commented).

However for other reasons I have to have the third line below set the geometry of other items (text, columns, ...). With the 3rd line uncommented, the grid is therefore only present in the (3cm,2.5cm) margins you see defined in that line. It doesn't go all the way to the edges of the page.

So -- how do I keep the 3rd line below, but still have the grid go all the way to the edges of the paper?

\documentclass[11pt, twocolumn]{book}
%\usepackage[margin=0in,footskip=0in]{geometry} % WORKS IF I USE THIS
\usepackage[top=3cm,bottom=3cm,left=2.5cm,right=2.5cm,letterpaper]{geometry} % DOESN'T WORK IF I USE THIS

\usepackage{tikz}  
\newcommand{\mygraphpaper}{%Make a grid
    \begin{tikzpicture}
        \draw[line width=.4pt,draw=black!30] (0,0) grid[step=2em] (\textwidth,\textheight);
        \draw[line width=.4pt,draw=red!50] (0,0) grid[step=20em] (\textwidth,\textheight);
    \end{tikzpicture}%
}

\usepackage{background} %Put a grid in the background
\backgroundsetup{contents=\mygraphpaper, opacity=0.3, scale=1,  angle=0, vshift=0.0cm, hshift=0.0cm}

\begin{document}
    Here is some text
\end{document}

Not correct enter image description here

1 Answer 1

4

Use the current page node (see TikZ/PGF manual, section 17.13.2, Referencing the Current Page Node – Absolute Positioning):

\newcommand{\mygraphpaper}{%Make a grid
    \begin{tikzpicture}[remember picture, overlay]
      \draw[line width=.4pt,draw=black!30]
      (current page.north east) grid[step=2em] (current page.south west);
      \draw[line width=.4pt,draw=red!50]
      (current page.north east) grid[step=20em] (current page.south west);
    \end{tikzpicture}%
}

where I added the options remember picture and overlay (see the manual).

Example:

\documentclass[11pt, twocolumn]{book}
%\usepackage[margin=0in,footskip=0in]{geometry} % WORKS IF I USE THIS
\usepackage[top=3cm,bottom=3cm,left=2.5cm,right=2.5cm,letterpaper]{geometry} % DOESN'T WORK IF I USE THIS

\usepackage{tikz}
\newcommand{\mygraphpaper}{%Make a grid
    \begin{tikzpicture}[remember picture, overlay]
      \draw[line width=.4pt,draw=black!30]
      (current page.north east) grid[step=2em] (current page.south west);
      \draw[line width=.4pt,draw=red!50]
      (current page.north east) grid[step=20em] (current page.south west);
    \end{tikzpicture}%
}

% \usepackage{background} %Put a grid in the background
% \backgroundsetup{contents=\mygraphpaper, opacity=0.3, scale=1,  angle=0, vshift=0.0cm, hshift=0.0cm}

\begin{document}
  \mygraphpaper
    Here is some text
\end{document}

Example

You must log in to answer this question.

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