Here is a solution via pgfkeys
.
First, I create the new family mygrid
, I define some keys with their initial values in this family and I define the new command \mygridset
to use this family:
\pgfkeys{
mygrid/.is family,
mygrid,
min x/.initial=-5,
max x/.initial=5,
min y/.initial=-5,
max y/.initial=5,
small step/.initial=.1,
step/.initial=1,
big step/.initial=5,
color/.initial=red,
}
\newcommand\mygridset[1]{\pgfkeys{mygrid,#1}}
Then I define the new command \mygrid
with an empty optional parameter. The first lines of this command (the call to \mygridset
) changes the values of the keys via #1
then store the value of each key in a macro. The last lines draw the grid with these values.
\newcommand\mygrid[1][]{
\mygridset{#1,
min x/.get=\gridminx,
max x/.get=\gridmaxx,
min y/.get=\gridminy,
max y/.get=\gridmaxy,
small step/.get=\gridsmallstep,
step/.get=\gridstep,
big step/.get=\gridbigstep,
color/.get=\gridcolor
}
\draw [step=\gridsmallstep, help lines,\gridcolor!20]
(\gridminx,\gridminy) grid (\gridmaxx,\gridmaxy);
\draw [step=\gridstep, help lines,\gridcolor!40]
(\gridminx,\gridminy) grid (\gridmaxx,\gridmaxy);
\draw [step=\gridbigstep, help lines,\gridcolor!100]
(\gridminx,\gridminy) grid (\gridmaxx,\gridmaxy);
\foreach \x in {\gridminx,...,\gridmaxx} {
\node[below,font=\tiny] at (\x,\gridminy) {$\x$};
\node[above,font=\tiny] at (\x,\gridmaxy) {$\x$};
};
\foreach \y in {\gridminy,...,\gridmaxy} {
\node[left,font=\tiny] at (\gridminx,\y) {$\y$};
\node[right,font=\tiny] at (\gridmaxx,\y) {$\y$};
};
}
Here is a complete example (3 pages) to illustrate the usage:
And the complete code:
\documentclass[tikz]{standalone}
\pgfkeys{
mygrid/.is family,
mygrid,
min x/.initial=-5,
max x/.initial=5,
min y/.initial=-5,
max y/.initial=5,
small step/.initial=.1,
step/.initial=1,
big step/.initial=5,
color/.initial=red,
}
\newcommand\mygridset[1]{\pgfkeys{mygrid,#1}}
\newcommand\mygrid[1][]{
\mygridset{#1,
min x/.get=\gridminx,
max x/.get=\gridmaxx,
min y/.get=\gridminy,
max y/.get=\gridmaxy,
small step/.get=\gridsmallstep,
step/.get=\gridstep,
big step/.get=\gridbigstep,
color/.get=\gridcolor
}
\draw [step=\gridsmallstep, help lines,\gridcolor!20]
(\gridminx,\gridminy) grid (\gridmaxx,\gridmaxy);
\draw [step=\gridstep, help lines,\gridcolor!40]
(\gridminx,\gridminy) grid (\gridmaxx,\gridmaxy);
\draw [step=\gridbigstep, help lines,\gridcolor!100]
(\gridminx,\gridminy) grid (\gridmaxx,\gridmaxy);
\foreach \x in {\gridminx,...,\gridmaxx} {
\node[below,font=\tiny] at (\x,\gridminy) {$\x$};
\node[above,font=\tiny] at (\x,\gridmaxy) {$\x$};
};
\foreach \y in {\gridminy,...,\gridmaxy} {
\node[left,font=\tiny] at (\gridminx,\y) {$\y$};
\node[right,font=\tiny] at (\gridmaxx,\y) {$\y$};
};
}
% a style to memorize some change to the default values
\mygridset{
a grid/.style={
min x=-3,
max x=3,
min y=-3,
max y=3,
small step=.2,
step=1,
big step=2,
color=orange,
}
}
\begin{document}
\begin{tikzpicture}
% a grid with default values
\mygrid
\end{tikzpicture}
\begin{tikzpicture}
% a grid with specific values
\mygrid[min x=-3, max x=2,min y=-2,max y=1,color=blue]
\end{tikzpicture}
\begin{tikzpicture}
% a grid using the `a grid` style
\mygrid[a grid]
\end{tikzpicture}
\end{document}
I don't really get the question so I hope this is what you wanted. If you include a full document (such that we copy paste and see the problem on our systems) things are much more easier.
Here, you can change the default setting within a scope but your block
style had a node distance
which was resetting every time it is issued. I've made it 2mm such that we can see the difference easier.
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}[decision/.style={diamond, draw, text width=4.5em, text badly centered, node distance=3.5cm, inner sep=0pt},
block/.style ={rectangle, draw, text width=6em, text centered, rounded corners, minimum height=4em, minimum height=2em},
cloud/.style ={draw, ellipse, minimum height=2em},
line/.style ={draw,-latex'},
node distance = 1cm,
auto]
\node [block] (1st) {1st};
\node [block, right= of 1st] (2nd1) {2nd1};
\begin{scope}[node distance=2mm and 10mm]%Here we change it for everything inside this scope
\node [block, above= of 2nd1] (2nd2) {2nd2};
\node [block, below= of 2nd1] (2nd3) {2nd3};
\node [block, right= of 2nd1] (3rd1) {3rd1};
\node [block, above= of 3rd1] (3rd2) {3rd2};
\node [block, above= of 3rd2] (3rd3) {3rd3};
\end{scope}
\node [block, below= of 3rd1] (3rd4) {3rd4};
\node [block, below= of 3rd4] (3rd5) {3rd5};
\path [line] (1st) -- (2nd1);
\path [line] (2nd1) -- (2nd2);
\path [line] (2nd1) -- (2nd3);
\path [line] (2nd2) -- (3rd3);
\path [line] (2nd1) -- (3rd1);
\path [line] (1st) -- (2nd1);
\end{tikzpicture}
\end{document}
Best Answer
As far as I understand you want a simple line over four points with an arrow at the end, so you don't need the edge-tool. Without the plot (which I can't compile without a MWE), this should create what you want: