# How to fine tune rotation of text along circular path?

After searching the web and finally coming from here (recreating a logo), I couldn't find an answer to what I am looking for. I want to rotate a text inside a circle and have a full control/fine tuning over its rotation, I stuck with the "Unknown" text, I couldn't make it rotate further down to get it centrally aligned with regard to the two yellow and red rectangles, i.e. the "kn" part of "Unknown" should face the white line between the two rectangles as in the figure below

based on the code below:

\documentclass[12pt]{scrreprt}
\usepackage{courier} %courier font
\usepackage{pgf,tikz,xcolor} % for tikz graphs and colors
\usetikzlibrary{decorations.text} % decorations.text for the text along path feature
\pagestyle{empty} % to suppress page numbers
\begin{document}
\begin{figure}[htbp]
\begin{tikzpicture}
\draw[color=black,fill=yellow,fill opacity=1.0] (2.87,-0.98) -- (2.51,-2.05) -- (4.39,-2.66) -- (4.76,-1.6) -- cycle;% yellow rect
\draw[color=black,fill=red,fill opacity=1.0] (3.23,0.19) -- (5.12,-0.43) -- (4.81,-1.5) -- (2.92,-0.88) -- cycle; %red rect
\draw[double distance=10mm,double=gray,opacity=0.3](0,0) circle (4.4cm); % a double circle
\path [postaction={decorate,decoration={raise=-1ex,text along path, reverse path,text align=center, text={|\ttfamily\huge\color{white}|Text label 1}}}] (-36:4.4cm) arc (-36:216:4.4cm); % commands should be between delimiters ||
\path [postaction={decorate,decoration={raise=-1ex,text along path, reverse path,text align=right, text={|\ttfamily\huge\color{white}|Unknown}}}] (-36:4.4cm) arc (-36:144:4.4cm);
\path [postaction={decorate,decoration={raise=-1ex,text along path,text align=right, text={|\ttfamily\huge\color{white}|Text label 2}}}] (-36:4.4cm) arc (-36:288:4.4cm);
\end{tikzpicture}
\end{figure}
\end{document}


Also related to my question:
1. Can I do all of the text in one \path command?
2. Can I do text along a path directly using the circle as my path, I mean without the need to draw an arc?
3. It would be great if this can be done with few lines of code.
4. Is there any specialized packages/tikz (tikz fan!) libraries to get user-friendly control over text along any path anywhere in the cloud?

-
Welcome to TeX.SE, and thank you for providing a complete MWE including \documentclass that sets up the problem. –  Peter Grill Mar 23 '13 at 9:16

Text decorations are somewhat tricky because the text is chopped up into letters and they are rotated according to the underlying path. The decoration library has many options for aligning the text on the path for example it can distribute words along the path depending on whether it sees a whitespace via align={fit to path stretching spaces} or you can spread all letters etc. The manual is pretty comprehensive on these options. Here you can use a simple circle for the decoration but there are a few issues.

1. You have three groups of text to be separated apart.
2. Those groups include whitespace chars
3. The circle is always drawn starting from the zero angle (rightmost point)
4. Because the circle is a closed path the space stretching drives the last group to the first group thinking that the last one should be shifted to the end of the path. Hence first and last group is combined on the right side. We need an invisible element in the end trailing a whitespace char so that the path is divided into three pieces.

So to handle the first issue, we separate three word groups with spaces.

To handle the second issue we replace the whitespaces within the word groups by \space command (the whitespace after \space is gobbled so no worries). So TikZ doesn't see the whitespace but the command expands to a whitespace

To handle the third, we rotate the path instead of aligning the decorations.

To handle the fourth issue we put a whitespace and a \space command as ␣\space

The end result looks like this

\documentclass[12pt]{scrreprt}
\usepackage{courier} %courier font
\usepackage{tikz} % for tikz graphs and colors
\usetikzlibrary{decorations.text} % decorations.text for the text along path feature
\pagestyle{empty} % to suppress page numbers

\begin{document}

\begin{tikzpicture}
\draw[color=black,fill=yellow,fill opacity=1.0] (2.87,-0.98) -- (2.51,-2.05) -- (4.39,-2.66) -- (4.76,-1.6) -- cycle;% yellow rect
\draw[color=black,fill=red,fill opacity=1.0] (3.23,0.19) -- (5.12,-0.43) -- (4.81,-1.5) -- (2.92,-0.88) -- cycle; %red rect
%\draw[double distance=10mm,double=gray,opacity=0.3](0,0) circle (4.4cm); % a double circle
\draw [double distance=10mm,
double=gray,
draw opacity=0.3,
rotate=120,
postaction={
decorate,
decoration={
raise=-1ex,
text along path,
reverse path,
text align={fit to path stretching spaces},
text={|\ttfamily\huge\color{white}|Text\space label\space 1 Unknown Text\space Label\space 2 \space}
}
}
] (0,0) circle (4.4cm);
\end{tikzpicture}

\end{document}


Now you can play around with rotation amount further or insert other elements at the end of the path to change the spacing etc. If you use draw opacity the text decoration won't be affected from the transparency.

EDIT : To fix the flow direction of Text label 2 within the same path.

\documentclass[12pt]{scrreprt}
\usepackage{courier} %courier font
\usepackage{tikz} % for tikz graphs and colors
\usetikzlibrary{decorations.text} % decorations.text for the text along path feature
\pagestyle{empty} % to suppress page numbers

\begin{document}

\begin{tikzpicture}
\draw[color=black,fill=yellow,fill opacity=1.0] (2.87,-0.98) -- (2.51,-2.05) -- (4.39,-2.66) -- (4.76,-1.6) -- cycle;% yellow rect
\draw[color=black,fill=red,fill opacity=1.0] (3.23,0.19) -- (5.12,-0.43) -- (4.81,-1.5) -- (2.92,-0.88) -- cycle; %red rect
%\draw[double distance=10mm,double=gray,opacity=0.3](0,0) circle (4.4cm); % a double circle
\draw [double distance=10mm,
double=gray,
draw opacity=0.3,
rotate=150,
postaction={
decorate,
decoration={
raise=-1ex,
text along path,
reverse path,
text align={fit to path stretching spaces,right indent=12cm},
text={|\ttfamily\huge\color{white}|Text\space label\space 1 Unknown}
}
},
postaction={
decorate,
decoration={
raise=-1ex,
text along path,
%reverse path,
text align={left indent=3cm,right indent=9cm},%or right indent=15cm,center
text={|\ttfamily\huge\color{white}|Text label 2}
}
}
] (0,0) circle (4.4cm);
\end{tikzpicture}

\end{document}


It can be adjusted further with the right/left indent keys

-
The Text Label 2 is upside down. –  g.kov Mar 23 '13 at 14:46
I couldn't upvote more! thanks a lot for having it in one path. How can we fix the text of label 2 by another path, can you add this so we have a complete answer? –  doctorate Mar 23 '13 at 14:56
@doctorate Thanks. I think you can use the same approach in the question you have linked. Now it needs to be two arcs one from, say \draw (120:4cm) arc (-240:-360:4cm); (to draw clockwise) and the rest. Then you can stretch space the first and center align the second to get a proper spacing. Or you use two \postactions with the same paath –  percusse Mar 23 '13 at 15:10

I'm not quite sure I understood your problem. Here's what I think solves your problem:

\documentclass[12pt]{scrreprt}
\usepackage{courier} %courier font
\usepackage{pgf,tikz,xcolor} % for tikz graphs and colors
\usetikzlibrary{decorations.text} % decorations.text for the text along path feature
\pagestyle{empty} % to suppress page numbers
\begin{document}
\begin{figure}[htbp]
\begin{tikzpicture}
\draw[color=black,fill=yellow,fill opacity=1.0] (2.87,-0.98) -- (2.51,-2.05) -- (4.39,-2.66) -- (4.76,-1.6) -- cycle;% yellow rect
\draw[color=black,fill=red,fill opacity=1.0] (3.23,0.19) -- (5.12,-0.43) -- (4.81,-1.5) -- (2.92,-0.88) -- cycle; %red rect
\draw[double distance=10mm,double=gray,opacity=0.3](0,0) circle (4.4cm); % a double circle
\path [draw,line width=5pt,red,postaction={decorate,decoration={raise=-1ex,text along path, reverse path,text align=center, text={|\ttfamily\huge\color{white}|Text label 1}}}] (-36:4.4cm) arc (-36:216:4.4cm); % commands should be between delimiters ||
\path [draw,line width=3pt,green,postaction={decorate,decoration={raise=-1ex,text along path, reverse path,text align=right, text={|\ttfamily\huge\color{white}|Unknown}}}] (-36:4.4cm) arc (-36:144:4.4cm);
\path [draw,line width=1pt,blue,postaction={decorate,decoration={raise=-1ex,text along path,text align=right, text={|\ttfamily\huge\color{white}|Text label 2}}}] (-36:4.4cm) arc (-36:288:4.4cm);
\draw(0,0)--(-36:5) node[right]{-36};
\draw(0,0)--(144:5) node[right]{144};
\draw(0,0)--(216:5) node[right]{216};
\draw(0,0)--(288:5) node[right]{288};
\end{tikzpicture}
\end{figure}

\begin{tikzpicture}
\draw[color=black,fill=yellow,fill opacity=1.0] (2.87,-0.98) -- (2.51,-2.05) -- (4.39,-2.66) -- (4.76,-1.6) -- cycle;% yellow rect
\draw[color=black,fill=red,fill opacity=1.0] (3.23,0.19) -- (5.12,-0.43) -- (4.81,-1.5) -- (2.92,-0.88) -- cycle; %red rect
\draw[double distance=10mm,double=gray,opacity=0.3](0,0) circle (4.4cm); % a double circle
\path [draw,line width=5pt,red,postaction={decorate,decoration={raise=-1ex,text along path, reverse path,text align=center, text={|\ttfamily\huge\color{white}|Text label 1}}}] (-36:4.4cm) arc (-36:216:4.4cm); % commands should be between delimiters ||
\path [draw,line width=3pt,green,postaction={decorate,decoration={raise=-1ex,text along path, reverse path,text align=right, text={|\ttfamily\huge\color{white}|Unknown}}}] (-39:4.4cm) arc (-39:144:4.4cm);
\path [draw,line width=1pt,blue,postaction={decorate,decoration={raise=-1ex,text along path,text align=right, text={|\ttfamily\huge\color{white}|Text label 2}}}] (-36:4.4cm) arc (-36:288:4.4cm);
\draw(0,0)--(-36:5) node[right]{-36};
\draw(0,0)--(-39:5) node[right]{-39};
\draw(0,0)--(144:5) node[right]{144};
\draw(0,0)--(216:5) node[right]{216};
\draw(0,0)--(288:5) node[right]{288};
\end{tikzpicture}

\end{document}


I added the path to show you the difference:

The text "Unknown" is typed along the green path aligned at the right end. You set that end to be at -36°. Changing that to -39° lets the path begin in a position, where the "kn" faces the gap between the rectangles. (My English isn't that well. Maybe I understand these words wrong.)

Concerning doing this in one path command: Try using subpaths which can be decorated as well. I haven't tried for myself, but section 21.2 of the pgf-manual covers that question explicitly.

-

This alternative example uses an Asymptote module labelpath which is based on PSTricks pstextpath macro and hence it does not work with pdfLaTeX. You can adjust a rotation angle by changing shift parameter sh. The following file ring.asy results in a ring.eps via asy ring.asy command.

import labelpath;
size(150);
guide g=unitcircle;

guide[] ring=(scale(1.15)*unitcircle)^^(scale(0.95)*unitcircle);
fill(ring,evenodd+gray(163/255));

guide g1,g2,g3;
real t0,t1,t2,t3;

real L=arclength(g);

real sh=-0.0135L;

t0=arctime(g,sh+0.0);
t1=arctime(g,sh+L/3);
t2=arctime(g,sh+2L/3);
t3=arctime(g,sh+L);

g1=subpath(g,t0,t1);
g2=subpath(g,t1,t2);
g3=subpath(g,t2,t3);

draw(g1,red);
draw(g2,green);
draw(g3,blue);

pen textpen=gray(1);
labelpath("\texttt{Text label 1}",reverse(g1),LeftJustified,textpen);
labelpath("\texttt{Text label 2}",scale(1.12)*g2,RightJustified,textpen);
labelpath("\texttt{Unknown}",reverse(g3),LeftJustified,textpen);

transform t=rotate(-15)*shift(1,0)*scale(0.4,0.2)*shift(-0.5,-0.5);
guide rbox=t*unitsquare;
pair u=point(rbox,0);
pair v=point(rbox,3);
pair w=(u-v)*1.1;
guide ybox=shift(w.x,w.y)*rbox;

filldraw(rbox,red,black);
filldraw(ybox,rgb(1,241/255,0),black);


3. Depends on a definition of a few and a length of a line. I think, you can join all the lines of the example to get one line.