24

Once in a while I have to create a layout given by several parameters, such as "left margin 3cm, logo 4 cm from the right margin, 2cm high" etc. Now I use geometry package an other helpers to create a layout, but I need to print out the result in order to check if everything is correct (well, I use Acrobat for that, but not everyone has access to it).

What I am thinking: is there a package to put graph paper with a 1cm grid (and millimeter ticks) in the background, so I could easily check if my layout is correct?

lockstep
  • 250,273
topskip
  • 37,020
  • I'm just adding a tikz-pgf tag, because I'm sure someone (not me though) will very soon write down a solution using that package. – yo' Feb 13 '12 at 11:09
  • I haven't tried this. Can you use the wallpaper package with a graph paper as a background image? There are options in that package to make the background image fit the page. – Sony Feb 13 '12 at 11:16
  • @Sony Hehe, I am ignoring the 'tikz-pgf' label and couldn't see my own question after you have added the label. "Why is TeX.SX eating my question" I thought. :) – topskip Feb 13 '12 at 11:23
  • @tohecz oh, wrong addressee in my last comment. – topskip Feb 13 '12 at 11:46
  • Sorry for confusing you. – yo' Feb 13 '12 at 11:54

2 Answers2

32

I think the »eso-pic« package provides any easy method to get what you want.

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[
  grid,
  gridcolor=red!20,
  subgridcolor=green!20
]{eso-pic}
\usepackage{lipsum}

\begin{document}
  \lipsum[1-4]
\end{document}

The grid is customizable in many ways. The package manual has more details.


enter image description here

8

A TikZ solution might look like this.

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}[remember picture, overlay]
    \draw[very thin, green!20,step=1mm,xshift=7.5mm,yshift=7.5mm] (current page.south west) grid (current page.north east);
    \draw[very thin, red!20,step=1cm,xshift=7.5mm,yshift=7.5mm] (current page.south west) grid (current page.north east);
  \end{tikzpicture}
\end{document}

I am not entirely sure why the shifting is necesarry, but it is if you want the grid to 'start' at the top left.

Edit: Here is a robust solution:

\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture, overlay,shift={(current page.north west)}]
  \draw[very thin, blue!10,step=2mm]
  (current page.south west) grid (current page.north east);
  \draw[very thin, red!20,step=1cm]
  (current page.south west) grid (current page.north east);
\end{tikzpicture}
\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
Roelof Spijker
  • 17,663
  • 5
  • 55
  • 63
  • The shift appears to be an artifact of the document class. For memoir, the xshift is 3.5mm and the yshift 8.0mm. But drawing a line between the SW and NE co-ordinates appears to be correct, relative to the page. ¿Go figure? – Brent.Longborough Feb 13 '12 at 13:50
  • I think we can use \pgftransformcm{1}{0}{0}{1}{\pgfpoint{7.5mm}{7.5mm}} to shift the whole picture. – percusse Feb 13 '12 at 18:13
  • @percusse: Yeah, I can also apply the shift on the tikzpicture, no reason to use the coordinate transformation matrix. I was more wondering why this was necessary in the first place... If I do \draw (0,0) grid (3,3) there isn't an offset I need to compensate for, so why is there when using the current page node? – Roelof Spijker Feb 13 '12 at 18:32
  • See also: http://tex.stackexchange.com/questions/44416/is-memoirs-page-layout-incompatible-with-tikz – Brent.Longborough Feb 13 '12 at 20:49
  • @Brent.Longborough: That looks fine in an article though. The rectangle is exactly the page in that case. It also works fine for memoir if you remove all of the trimming and margining commands, so... – Roelof Spijker Feb 14 '12 at 13:09
  • @RoelofSpijker: Oh, yes, of course. While I'm not complaining, I think it's a bug/omission, and the definition of "current page" is definitely imprecise, as it currently looks like "from the south west corner of the stock, a rectangle that is paperwidth by paperheight" – Brent.Longborough Feb 14 '12 at 13:16
  • @Brent.Longborough: I certainly agree that the definition is lacking. I don't think that your definition is entirely accurate either though, since that wouldn't explain the shift in the grid. Perhaps the grid in combination with the current page node are causing the issue here. Since the current page node without a grid seems to correspond to the correct place in a regular article and if I just use the grid as I did in one of my previous comments it starts where expected. Perhaps I will try and analyze this a little further today, if I have the time. – Roelof Spijker Feb 14 '12 at 13:30
  • Yours shifting operations must be changed if you choose another paper size (a4paper for example): grid is always at origin. Add shift={(current page.north west)} within global options of tikzpicture to solve this problem. – Paul Gaborit Jun 15 '12 at 01:11
  • @RoelofSpijker I have completed your solution with my suggestion... – Paul Gaborit Jun 15 '12 at 01:17