If you want to put something into a macro, first figure out how to produce what you want. For example, say you come up with this solution to drawing what you want.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw
(0, 0) node [left] {$7$} --
(1.5cm, 0) --
(1.5cm,2.5cm) node [above] {$8$} --
(0, 2.5cm) node [above] {$4$} node [left] {$1$} --
cycle;
\draw [draw=none] (0,0)--(1.5cm,2.5cm) node [midway] {Text};
\end{tikzpicture}
\end{document}
Then to make a macro put the entire tikzpicture environment in a \newcommand and replace the approriate portions with #1, #2, etc...
\newcommand{\DrawRectangle}[6]{% length, height, labelSW, labelNW, labelWN, labelEN
\begin{tikzpicture}
\draw
(0, 0) node [left] {#3} --
(#1, 0) --
(#1,#2) node [above] {#6} --
(0, #2) node [above] {#5} node [left] {#4} --
cycle;
\draw [draw=none] (0,0)--(#1,#2) node [midway] {Text};
\end{tikzpicture}
}
\begin{document}
\DrawRectangle{1.5cm}{2.5cm}{$7$}{$1$}{$4$}{$8$}
\end{document}
If you require a lot of flexibility you will run out of parameters (since you can only have 9). One solution is to use styles and set default values within the macro using the \providetikzstyle like macros.
append after commandkeys, instead of just one? – Jake Sep 03 '11 at 00:15\tikzlastnodegetting renamed) and separating them out helped me figure out what was going on. I've just tested it and there's no reason to have them separate. I'll edit. – Andrew Stacey Sep 03 '11 at 14:46ERROR: LaTeX Error: File "standalone.cls" not found., do you know where I can find this file? – SoftTimur Sep 03 '11 at 20:11documentclass{minimal}, it gives me anERROR: Package pgfkeys Error: I do not know the key '/tikz/my funny rectangle/.style n args' and I am going to ignore it. Perhaps you misspelled it.– SoftTimur Sep 03 '11 at 20:13standaloneclass is a class developed by Martin Scharrer for producing documents just as big as their contents which makes them great for producing the pictures here. I should have changed that toarticlewhen posting the code. Theminimalclass should almost never be used. Try again witharticle. – Andrew Stacey Sep 03 '11 at 21:26style n argswas introduced in that. – Andrew Stacey Sep 03 '11 at 21:27documentclass{article}, but the error remains... Indeed, i am using PGF 2.00 instead of 2.10. I have post another thread – SoftTimur Oct 16 '11 at 16:08