7

Is there a way to get label text to rotate with the TikZ node to which it is attached. I can rotate the node and its text; but labels do not rotate along with the node, and instead remain "level":

\tikzset{fig/.style={regular polygon, regular polygon sides=3, label=60:A,label=below:B}}
\begin{tikzpicture} 
\foreach \i in {0,1,2,3}{\node[fig,rotate=20*\i,draw] at(\i*4,0) {Text};}
\end{tikzpicture}

enter image description here

In general, I'd like to find a way to rotate a "composite" element, consisting of more than just a single, simple node and it's labels; for example, a shape, in which the corners have been "marked" with symbols or other shapes:

enter image description here


\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}
% Not needed for MWE but used in my code:
%\usetikzlibrary{positioning}
%\usetikzlibrary{petri}

\begin{document}

\tikzset{fig/.style={regular polygon, regular polygon sides=3, label=60:A,label=below:B}}
\begin{tikzpicture} 
\foreach \i in {0,1,2,3}{\node[fig,rotate=20*\i,draw] at(\i*4,0) {Text};}
\end{tikzpicture}

% I don't know how to create the images in the second illustration

\end{document}
  • It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Especially with tikz since there are so many libraries. – Peter Grill May 26 '12 at 5:04
  • @PeterGrill: Added. I don't have on for the second image though (my ideal goal): I'm not sure how to build the figures illustrated there. – orome May 26 '12 at 5:13
  • 1
    A boring construction of the shape: \begin{tikzpicture} \node[draw,regular polygon,regular polygon sides=3,minimum height=1cm] (a) {}; \node[anchor=north,regular polygon,regular polygon sides=3,fill=gray!50,minimum height=0.3cm,inner sep=0] at (a.north) {}; \node[fill,circle,inner sep=1.5pt] at ([shift={(-2mm,1.2mm)}]a.corner 3) {}; \end{tikzpicture} Otherwise, you can declare a new shape and inherit the important parts from a triangle. – percusse May 26 '12 at 9:13
  • @percusse: Thanks, that will get me on track to exactly what I'm trying to do. – orome May 26 '12 at 15:39
7
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\begin{document}

\begin{tikzpicture} [fig/.style={regular polygon, regular polygon sides=3}]
\foreach \i in {0,1,2,3}{%
    \begin{scope} [rotate around={20*\i:(\i*4,0) },every node/.style={transform shape}]
        \node[fig,draw] (t) at (\i*4,0) {Text};
        \node at ([shift={(60:8pt)}]t.60)  {A}; % I prefer more possibilities
        \node at ([yshift=-8pt]t.south)  {B};   % I prefer more possibilities
    \end{scope}

}
\end{tikzpicture}
\end{document} 

enter image description here

or with your code and like in Peter's answer remark : a local style is better (fig/.style here is a local style)

\begin{tikzpicture}[fig/.style={regular polygon, regular polygon sides=3, label=60:A,label=below:B}] 
\foreach \i in {0,1,2,3}{
    \begin{scope}[rotate around={20*\i:(\i*4,0) }, ultra thick, transform shape]
        \node[fig,draw] at(\i*4,0) {Text};
    \end{scope}
}
\end{tikzpicture} 
| improve this answer | |
6

If you wrap the contents within a scope and rotate the entire scope, the text will also rotate (and include transform shape option):

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\tikzset{fig/.style={regular polygon, regular polygon sides=3, label=60:A,label=below:B}}

\begin{tikzpicture} 
\foreach \i in {0,1,2,3}{
    \begin{scope}[rotate around={20*\i:(\i*4,0) }, ultra thick, transform shape]
        \node[fig,draw] at(\i*4,0) {Text};
    \end{scope}
}
\end{tikzpicture}
\end{document}
| improve this answer | |
  • I need the figures to be at the ("at") specified positions though. – orome May 26 '12 at 5:17
  • 2
    rotate around={20*\i:(\i*4,0) } is enough to do that – Alain Matthes May 26 '12 at 5:30

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.