[Tex/LaTex] How to fine tune rotation of text along circular path

circlespathsrotatingtext-decorationstikz-pgf

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
enter image description here

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?

Best Answer

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}  

enter image description here

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}  

enter image description here

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

Related Question