25

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

1 Answer 1

27

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}
4
  • It works without decorate too. Any reason to include \usetikzlibrary{decorations}?
    – mythealias
    Oct 7, 2012 at 13:45
  • @mythealias: Was left over from an earlier attempt at a fix. Have updated solution to removed it. Oct 7, 2012 at 18:17
  • 2
    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, 2015 at 18:30
  • 1
    shape border rotate does not work for all symbols.
    – scriptfoo
    Jun 23, 2023 at 14:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .