8

I have created a pic with TikZ 3.0 that includes an \includegraphics statement, and a label above a path with the arguments [sloped, above, midway].

The intention of the pic is to reuse it in other parts of my code. At times, I want to rotate the entire pic. However, the graphic and the label are unaffected.

Here is an MWE:

\documentclass{article}

\usepackage{tikz}

\begin{document}
\tikzset{
    testpic/.pic={
        \node at (3,0) {\includegraphics[width=1cm] {Rock.png}}; 
        \draw (0,0) -- (1,1) node [midway, sloped, above] {test}; 
    }
}

\begin{tikzpicture}
    \pic[rotate=90] {testpic};
\end{tikzpicture}

\end{document}

Here is the output:

The unrotated picture and label

As you can see, the rock is not rotated by 90 degree. It is intended that it is also rotated, as if I specified \includegraphics[angle=90]. The label above the path is also not rotated.

How can this be fixed?


Asset: enter image description here

lockstep
  • 250,273
Ingo
  • 20,035

1 Answers1

11

By default scaling or rotating do not apply to nodes. The reason is that normally the text should not be transformed even if the graphic is scaled or rotated.

If you wish to transform the nodes you have to add the option transform shape to the \pic command:

\documentclass[tikz,margin=5mm]{standalone}

\begin{document}
\tikzset{
  testpic/.pic={
    \node at (3,0) {\includegraphics[width=1cm] {Rock}}; 
    \draw (0,0) -- (1,1) node [midway, sloped, above] {test}; 
  }
}

\begin{tikzpicture}
  \pic[rotate=90,transform shape] {testpic};
\end{tikzpicture}

\end{document}

enter image description here

esdd
  • 85,675