19

How can I rotate the text inside a node independent of the node in tikz? Right now I am using the rotatebox. The other option I tried was to have two overlapping nodes. Is there a better way to do this?

\documentclass{standalone}
\usepackage{tikz}
    \usetikzlibrary{shapes.geometric}   % For trapezium
\usepackage{rotating}                   % For rotatebox
\begin{document}
\begin{tikzpicture}
% Text orientation is wrong
\node[draw, trapezium, rotate=-90, minimum height=1.2cm, trapezium stretches body] at (1,1.5) {Component};
% Method 1 using rotatebox
\node[draw, trapezium, rotate=-90, minimum height=1.2cm, trapezium stretches body] at (3,1.5) {\rotatebox{180}{Component}};
% Method 2 overlapping nodes
\node[draw, trapezium, rotate=-90, minimum height=1.2cm, trapezium stretches body, text=white] at (5,1.5) {Component};
\node[trapezium, rotate=90, minimum height=1.2cm, trapezium stretches body] at (5,1.5) {Component};
\end{tikzpicture}
\end{document}

Getting text orientation right

21

You can use shape border rotate=<anbgle> to rotate the shape. The combination rotate=90, shape border rotate=180 produces the shape and text rotated in the desired direction (as in first image):

enter image description here

Code:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}   % For trapezium 
\usepackage{rotating}               % For rotatebox

\begin{document}
\begin{tikzpicture}
% Text orientation is wrong
\node[draw, trapezium, rotate=90, minimum height=1.2cm, trapezium stretches body, shape border rotate=180] at (1,1.5)  {Component};
% Method 1 using rotatebox
\node[draw, trapezium, rotate=-90, minimum height=1.2cm, trapezium stretches body] at (3,1.5) {\rotatebox{180}{Component}};
% Method 2 overlapping nodes
\node[draw, trapezium, rotate=-90, minimum height=1.2cm, trapezium stretches body, text=white] at (5,1.5) {Component};
\node[trapezium, rotate=90, minimum height=1.2cm, trapezium stretches body] at (5,1.5) {Component};
\end{tikzpicture}
\end{document}
| improve this answer | |
  • It works without decorate too. Any reason to include \usetikzlibrary{decorations}? – mythealias Oct 7 '12 at 13:45
  • @mythealias: Was left over from an earlier attempt at a fix. Have updated solution to removed it. – Peter Grill Oct 7 '12 at 18:17
  • 1
    With the current version shape border rotate=-X does not seem to work, use shape border rotate=Y with Y=360-X instead. – ted Jun 24 '15 at 18: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.