2

I searching for a solution to define a node style whish includes a png-picture.

\documentclass[10pt]{article}
\usepackage{tikz}

\begin{tikzpicture}
   [
     PIC/.style n args = {1}
                         {align=center,
                          label={center:
                                 \includegraphics[scale=0.01,rotate=#1]{picture.png}
                                }
                         }
   ]

   \node[PIC={60}] (f) at (0,0) {};

\end{tikzpicture}
\end{document}

I tried some other versions with \node but I have no real idea...

Hope you can help - thanks.


Additionally an example with two parameters:

[...
PT/.style n args = {2}{circle,draw,align=center,
                       inner sep=1pt,label={#1:#2}}]
...
\node[PT={below}{1}] (PT) at (0,0) {};

This will fully pass the arguments. If I set these:

[...
PT/.style n args = {1}{circle,draw,align=center,
                       inner sep=1pt,label={#1:2}}]
...
\node[PT={below}] (PT) at (0,0) {};

it only pass b instead of below


Thanks to Jesse! I don't know what is better. To define a token or do some crasy things like this:

Var 1

[...
PT/.style n args = {1}{circle,draw,align=center,
                       inner sep=1pt,label={#1:2}}]
...
\node[PT={below}\ ] (PT) at (0,0) {};

Var 2

[...
PT/.style n args = {1}{circle,draw,align=center,
                       inner sep=1pt,label={#1:2}}]
...
\node[PT={below}{} ] (PT) at (0,0) {};
2

It seems that changing rotate into angle makes the error gone. Please check the following website for includggraphics commands http://en.wikibooks.org/wiki/LaTeX/Importing_Graphics

enter image description here

\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\def\ang{60}
\begin{document}
\begin{tikzpicture}
[PIC/.style n args ={1}{align=center,label={center:
\includegraphics[scale=0.25,angle=#1]{example-image-a}
}}
]
 \node[PIC={\ang}] (f) at (0,0) {};
\end{tikzpicture}
\end{document}

Edit: The OP observes that only the first character was passed to the argument (ie., only 6, not 60, was passed to the argument.) A remedy is to define a command called \ang via \def\ang{60}, then pass this \ang to the argument, as shown above in the the code. Same idea applies to the follow-up by the OP. The image is newly compiled result.

  • Yes - I was blind. This goes... In this case there are an bug: It passes only the letter. (In your case 60->6) What I have to add to get the whole value. – Alex44 Dec 30 '13 at 10:45
  • @Alex44 -- You are right. Please see my update where \ang=60 is defined at preamble and use \ang to replace 60 in the node option. – Jesse Dec 30 '13 at 10:57
  • Thanks - now it fully goes. The definition of an variable is a bit hacky ;) I don't understand, why it pass right with two arguments but not with one... – Alex44 Dec 30 '13 at 11:16
  • @Alex44 -- After a macro definition, \abc with the backlash becomes a unit, also known as a token. – Jesse Dec 30 '13 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.