7

I would like to make a custom node shape with a small picture (on north east) using the svg directive of TikZ, because the picture comes from a svg path.

As you can see with this simple code, the picture is clipped and I don't want to add text (aaaa) to make the attached node larger.

It would be great if you can show me how to operate a scale and a shift on this small picture. All my tests failed!

\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{svg.path}
\tikzset{ 
  t1/.style={rectangle,fill=blue!20},
  t2/.style={path picture={ \draw[fill=red,draw=blue] svg "M0,0L10,10L20,0L10,-10Z";} } 
}
\begin{tikzpicture}
\node[t1](A) at (1,1){A}; \draw(A.north east) node[t2]{aaaa};
\node[t1](B) at (2,1){B}; \draw(B.north east) node[t2]{};
\end{tikzpicture}
\end{document}
  • Welcome to TeX.SX! :) You don't need to add 'thank you' or sign your post. This is the way we keep it concise; your username automatically appears at the bottom of your posts. – Count Zero Jun 14 '12 at 16:10
6

I have drawn the shape centered around zero and smaller such that you can adjust the inner sep more comfortably.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{svg.path}
\tikzset{ 
  t1/.style={rectangle,fill=blue!20},
  t2/.style={inner sep = 2mm,path picture={ 
        \draw[fill=red,draw=blue] svg "M-3,0L0,3L3,0L0,-3Z";} 
        } 
}
\begin{document}
\begin{tikzpicture}
\node[t1](B) at (2,1){B}; \node[t2] at (B.north east) {};
\end{tikzpicture}
\end{document}

enter image description here

  • 2
    You're posting code faster than Lucky Luke is shooting! :D – Count Zero Jun 14 '12 at 16:11
  • The 'inner sep' fix my clipping problem, but what about shift and scale? I cannot change svg path data and I have to apply a 'shift+scale' on the small picture."\draw[fill=red,draw=blue,scale=.1] svg "M-30,0L0,30L30,0L0,-30Z";}" does not work. – pelinquin Jun 15 '12 at 8:11
  • @pelinquin Then you can see the edited version of my answer where I did a hack. After that modified to the current answer. You can add an xshift option to shift further. – percusse Jun 15 '12 at 8:25
  • @percusse. Sorry but I don't want xshift on the raw data. Why \draw[fill=red,draw=blue,scale=.1] svg "M-30,0L0,30L30,0L0,-30Z";} does not work? – pelinquin Jun 15 '12 at 8:49
  • @pelinquin You might want to provide the xshift to the node placement like at ([xshift-1cm]B.north east) when placing it. By the way this is required if you want to adjust further as a prediction ;) it is not essential. The reason for the weird behavior is that the path picture is clipped by the node shape with smaller size so you have to first make the node shape big enough such that it is visible and then scale it down. and after the scaling you might want to better position it. – percusse Jun 15 '12 at 9:01

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.