Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Use \pic[rotate=90,transform shape] {testpic}; –  esdd Apr 25 at 13:22
    
Well, that solved it. Why am I always missing the 'obvious' ;-)? Or, asked differently, why is that not the default option? –  Ingo Apr 25 at 13:23
    
@Ingo Because normally you use nodes for labeling your graph and don't want to rotate these when turning the rest. –  Henri Menke Apr 25 at 13:34

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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