5

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?

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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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