Skip to content

Edges on a grid

August 24, 2011

For drawing some extra edges in a grid I used the following code:

\begin{tikzpicture}
  \newcounter{xp}
  \newcounter{yp}
  \grGrid[prefix=a,RA=2,RB=2]{6}{6}
  \foreach \x in {0,2,4}{%
    \foreach \y in {1,3}{%
      \setcounter{xp}{\x}
      \setcounter{yp}{\y}
      \stepcounter{xp}
      \stepcounter{yp}
      \Edge(a\x;\y)(a\thexp;\theyp)
      }
    }
\end{tikzpicture}

For some reason the following code does not work (producing the error ! Package pgf Error: No shape named a1 is known.) Apparently, only counters are permitted as vertex indices.

\begin{tikzpicture}
  \grGrid[prefix=a,RA=2,RB=2]{6}{6}
  \foreach \x in {0,2,4}{%
    \foreach \y in {1,3}{%
      \pgfmathsetmacro{\xp}{\x+1}
      \pgfmathsetmacro{\yp}{\y+1}
      \Edge(a\x;\y)(a\xp;\yp)
      }
    }
\end{tikzpicture}
About these ads
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: