6

I would like to rotate a TikZ text node by a degree that depends on the content length. So a text node with 20 characters should be rotated e.g. 20*0.1 = 2 degree, a text node with 100 characters for 100*0.1 = 10 degree. It does not matter if whitespace influences this or not.

Is it possible to do that somehow automatically, or do I need to count letters manually?

8

This is an approximation. First, calculate the average character width, then create a new command to add the node with the rotation set to <length of node text>/<average character length> * 0.1.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\pgfmathsetmacro\characterlength{width("abcdefghijklmnopqrstuwxyz")/26}
\newcommand{\rotatenode}[3][]{\node [rotate=width("{#3}")/\characterlength*0.1,#1] at (#2) {#3};}
\begin{document}
\begin{tikzpicture}
\rotatenode[draw]{0,1}{abcdefghijklmnopqsrt}
\rotatenode[draw,red]{0,2}{abcdefghijklmnopqsrtabcdefghijklmnopqsrtabcdefghijklmnopqsrtabcdefghijklmnopqsrtabcdefghijklmnopqsrt}
\end{tikzpicture}
\end{document}

enter image description here

  • More than good enough approximation for my case, thanks! – TeXter Jan 24 '14 at 16:11

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.