2

I have modified code for rotating a primitive 'match' shape (adapted from rotating camera code found here (Use a custom shape as a "building block").

How do I pass the label parameter in the scope so each match is a different number. Now, all nodes are hardcoded to '2'

I am new to TikZ, so cannot understand exactly how to do it.

\documentclass{book}    
\usepackage{tikz}

\begin{document}  

\def\match#1#2{    
\begin{scope}[shift={#1}, rotate=#2]    
\draw (0,0) rectangle (2.5,0.2);    
\draw [fill=black](2.3,0.1) ellipse (0.35 and 0.2) node at (1,0.1)
[fill=white,opacity=.2,text opacity=1,circle, inner sep=0pt,minimum size=1pt]{\textbf{2}};    
\end{scope}    
}

\begin{tikzpicture}    
\match{(0,0)}{45}    
\match{(-0.3,-0.18)}{315}    
\match{(1.85,2.06)}{315}    
\match{(1.89,-1.89)}{45}    
\end{tikzpicture}    
\end{document}

1 Answers1

3

Pass the node text as third argument to \match:

enter image description here

\documentclass{book}
\usepackage{tikz}

\begin{document}

\newcommand\match[3]{%
    \begin{scope}[shift={#1}, rotate=#2]
    \draw (0,0) rectangle (2.5,0.2);
    \draw [fill=black](2.3,0.1) ellipse (0.35 and 0.2) node at (1,0.1)
        [fill=white,%
        opacity=.2,%
        text opacity=1,%
        circle,%
        inner sep=0pt,%
        minimum size=1pt]{\textbf{#3}};
    \end{scope}
}

\begin{tikzpicture}
    \match{(0,0)}{45}{4}
    \match{(-0.3,-0.18)}{315}{5}
    \match{(1.85,2.06)}{315}{3}
    \match{(1.89,-1.89)}{45}{1}
\end{tikzpicture}

\end{document}
jub0bs
  • 58,916