Created
October 9, 2014 20:12
-
-
Save anonymous/163af4eaa8e20cd284c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{tikz} | |
\makeatletter | |
\def\grd@save@target#1{% | |
\def\grd@target{#1}} | |
\def\grd@save@start#1{% | |
\def\grd@start{#1}} | |
\tikzset{ | |
simplegrid 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 | |
%% Extract coordinates | |
\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} | |
%% Grid | |
\draw (\tikztostart) grid (\tikztotarget); | |
%% Axes | |
\draw[black,thick] (\grd@xa, 0) -- (\grd@xb, 0) node[right] {}; | |
\draw[black,thick] (0, \grd@ya) -- (0, \grd@yb) node[above] {}; | |
%% Coordinates | |
%% ( change to {\grd@xa,\grd@xc,...,\grd@xb} for stepping ). | |
\foreach \x in {\grd@xa,...,\grd@xb} | |
\node[anchor=north] at (\x,\grd@ya) {% | |
\footnotesize{\pgfmathprintnumber{\x}}}; | |
\foreach \y in {\grd@ya,...,\grd@yb} | |
\node[anchor=east] at (\grd@xa,\y) {% | |
\footnotesize{\pgfmathprintnumber{\y}}}; | |
} | |
} | |
} | |
} | |
\makeatother | |
\begin{document} | |
\begin{tikzpicture} | |
\draw (0,0) to [simplegrid with coordinates] (6,6); | |
\end{tikzpicture} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment