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.