This question is a "follow up" of the question naming paths inside a TikZ foreach loop. I can construct the name of paths, but there are errors when using them to calculate intersection.
An example follows
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\newcommand{\modulargrid}{%
\begin{tikzpicture}[remember picture, overlay, ]
%% Trick to name paths:
%% https://tex.stackexchange.com/questions/5242/naming-paths-inside-a-tikz-foreach-loop
%% Draw horizontal lines
\foreach \x in {1,...,6} {
\edef\pathhone{name path global=horizontal\x}
\expandafter\draw\expandafter[\pathhone] ($
(current page.north west)
+ \x-1*(0,20pt-5cm)
$)
-- +(20cm, 0);
%% Draw vertical lines
\edef\pathvone{name path global=vertical\x}
\expandafter\draw\expandafter[\pathvone] ($
(current page.south west)
+ \x-1*(20pt+5cm,0)
$)
-- +(0,25cm);
}
\draw (0,0)--(0,0);
\fill[red, opacity=0.5, name intersections={of=vertical1 and horizonta1}]
(intersection-1) circle (2pt) node {1};
\end{tikzpicture}
}
\begin{document}
\modulargrid
\newpage
\end{document}
The purpose of the code
The idea behind this code is to make a grid of vertical and horizontal line, calculate the intersection points and them build rectangular shapes with the calculated points (I want to be able to each cell in the grid as a node.)
EDITED CODE
I edited the code according to the comment by @jake. (Sorry for the errors, due to coping an more complex example to a MWE.)
My problem is to use \i in the \fill command
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\newcommand{\modulargrid}{%
\begin{tikzpicture}[remember picture, overlay, ]
%% Trick to name paths:
%% https://tex.stackexchange.com/questions/5242/naming-paths-inside-a-tikz-foreach-loop
%% Draw horizontal lines
\foreach \x[count=\i] in {1,...,6} {
\draw[name path global=horizontal\i] ($
(current page.north west)
+ \x-1*(0,20pt-5cm)
$)
-- +(20cm, 0);
%% Draw vertical lines
\draw[name path global=vertical\i] ($
(current page.south west)
+ \x-1*(20pt+5cm,0)
$)
-- +(0,28cm);
\draw (0,0)--(0,0);
\fill[red, opacity=0.5, name intersections={of=vertical\i and horizontal\i}]
(intersection-1) circle (2pt) node {1};
}
\end{tikzpicture}
}
\begin{document}

horizonta1) is simply that the first horizontal and the first vertical line do not intersect: The first horizontal line is too high. If you change the-- +(0,25cm)to-- +(0,28cm), it works. Note that you don't need to go to all that trouble with the\edef: You can simply use\foreach \x [count=\i] ...to introduce an integer counter, and then use\draw [name path global=horizontal\i] (...in your loop. – Jake Apr 23 '13 at 14:49\iin thename intersections={of=vertical\i and horizontal\i}: You have to use1there (there's at most one intersection between two straight lines). Could you maybe edit your question to include in more detail what exactly you're trying to achieve? I have the feeling that you're going a very roundabout way, but I don't understand exactly what your final goal is. – Jake Apr 23 '13 at 15:17name intersections={of={vertical\i} and {horizontal\i}}with extra brackets to delimit the names. – Andrew Swann Apr 23 '13 at 15:19nodeswith the size and position of the "cells" in this grid. – TeXtnik Apr 23 '13 at 15:21