-
Notifications
You must be signed in to change notification settings - Fork 0
/
tikz-grid.tex
47 lines (45 loc) · 1.68 KB
/
tikz-grid.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
% Author: Julien Cubizolles
% Public domain
\def\grd@save@target#1{%
\def\grd@target{#1}}
\def\grd@save@start#1{%
\def\grd@start{#1}}
\tikzset{
grid with coordinates/.style={
to path={%
\pgfextra{%
\edef\grd@@target{(\tikztotarget)}%
\tikz@scan@one@point\grd@save@target\grd@@target\relax
\edef\grd@@start{(\tikztostart)}%
\tikz@scan@one@point\grd@save@start\grd@@start\relax
\draw[minor help lines] (\tikztostart) grid (\tikztotarget);
\draw[major help lines] (\tikztostart) grid (\tikztotarget);
\grd@start
\pgfmathsetmacro{\grd@xa}{\the\pgf@x/1cm}
\pgfmathsetmacro{\grd@ya}{\the\pgf@y/1cm}
\grd@target
\pgfmathsetmacro{\grd@xb}{\the\pgf@x/1cm}
\pgfmathsetmacro{\grd@yb}{\the\pgf@y/1cm}
\pgfmathsetmacro{\grd@xc}{\grd@xa + \pgfkeysvalueof{/tikz/grid with coordinates/major step}}
\pgfmathsetmacro{\grd@yc}{\grd@ya + \pgfkeysvalueof{/tikz/grid with coordinates/major step}}
\foreach \x in {\grd@xa,\grd@xc,...,\grd@xb}
{\node[anchor=north] at (\x,\grd@ya) {\pgfmathprintnumber{\x}};};
\foreach \y in {\grd@ya,\grd@yc,...,\grd@yb}
{\node[anchor=east] at (\grd@xa,\y) {\pgfmathprintnumber{\y}};};
}
}
},
minor help lines/.style={
help lines, opacity=.2,
step=\pgfkeysvalueof{/tikz/grid with coordinates/minor step}
},
major help lines/.style={
help lines, opacity=.2,
line width=\pgfkeysvalueof{/tikz/grid with coordinates/major line width},
step=\pgfkeysvalueof{/tikz/grid with coordinates/major step}
},
grid with coordinates/.cd,
minor step/.initial=.2,
major step/.initial=1,
major line width/.initial=2pt,
}