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.

I am drawing a grid on top of the layout defined with geometry.

\documentclass[letter]{article}
\usepackage{geometry}
\geometry{
    showcrop,
    paper = a4paper,
    layout = a5paper,
    layoutoffset={1cm,1cm}
}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}% just to generate text for the example

\makeatletter
% Code from:
% http://tex.stackexchange.com/questions/85064/grid-for-textpos-layout
\newcommand\rectangulargrid[2]{%
\tikz[
  remember picture,
  overlay,
  yscale=-1,
  xstep=\Gm@layoutwidth/#1,ystep=\Gm@layoutheight/#2,
  xshift= -\Gm@layouthoffset, yshift=-\Gm@layoutvoffset,
  ]
  \draw ($(current page.north west) - (\Gm@layouthoffset, \Gm@layoutvoffset)$) grid 
($(current page.north west)+ (\Gm@layoutwidth, \Gm@layoutheight) + (\Gm@layoutwidth/#1, \Gm@layoutheight/#2) $);}
\makeatother


\begin{document}
\lipsum[1-3]
\rectangulargrid{16}{16}
\end{document}

I don't know why the grid lines are not aligned with the crop marks.
Any idea?

share|improve this question

1 Answer 1

I achieve the same effect drawing the lines myself

\documentclass{article}
\usepackage{geometry}
\geometry{
    showcrop,
    paper = a4paper,
    layout = a5paper,
    layoutoffset={1cm,1cm}
}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}% just to generate text for the example

\makeatletter
\newcommand\rectangulargrid[2]{%
\begin{tikzpicture}[
  remember picture,
  overlay,
  yscale=-1,
  ]
  \draw[fill=red] ($(current page.north west) 
  + (\Gm@layouthoffset, \Gm@layoutvoffset)
  $)
  circle (5pt);
  \draw ($(current page.north west) 
  + (\Gm@layouthoffset, \Gm@layoutvoffset)
   $) -- + (0,-3cm);
  \draw ($(current page.north west) 
  + (\Gm@layouthoffset, \Gm@layoutvoffset)
   $) -- + (-3cm,0);

   \foreach \x in {0,...,#1}
       {
         \draw 
         ($
         (current page.north west) 
         + (\Gm@layouthoffset, \Gm@layoutvoffset)
         + \x*(\Gm@layoutwidth/#1, 0)
         $)
         -- +(0,\Gm@layoutheight);
       }

   \foreach \y in {0,...,#2}
       {
         \draw 
         ($
         (current page.north west) 
         + (\Gm@layouthoffset, \Gm@layoutvoffset)
         + \y*(0,\Gm@layoutheight/#2)
         $)
         -- +(\Gm@layoutwidth, 0);
       }


\end{tikzpicture}
}
\makeatother


\begin{document}
\lipsum[1-3]
\rectangulargrid{16}{16}
\end{document}
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.