5

How can I align text along the circumference of a circle like this using TikZ? Please ignore the icons. I tried using paths and decorations, but I don't know how to constrain the text to each sector.

This is the code I used to draw the circles and the sectors

\begin{tikzpicture}
    \draw[thick] (0cm,0cm) circle(3cm);
    \foreach \x in {0,45,...,360} {
            % lines from center to point
            \draw[black] (0cm,0cm) -- (\x:3cm);
                              }
     \end{tikzpicture}

enter image description here

  • 1
    Do you have the code for the circle and sectors without the text? Please add it to the question, so we a) can see how you've set things up and b) don't have to do everything from scratch. – Torbjørn T. May 23 '16 at 13:55
  • Sure, @TorbjørnT. – lexxie May 23 '16 at 14:04
  • Search for text along path in the PGFmanual or on this site to get an idea how to approach this. – Qrrbrbirlbel May 23 '16 at 19:48
  • Please always post a complete, minimal example. Can you make your code compilable and provide the text you want to use, maybe? – cfr May 23 '16 at 23:24
3

Metapost would give better results, but if you wish to use TikZ, decorations.text offers a variety of options.

For example:

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
  \draw [thick] (0,0) circle (3cm);
  \foreach \i/\j/\k in {0/something/tadpole,45/anything/cauldron,90/another/bread soup,135/whatever/rock candy,180/whenever/lollipop,225/whoever/Bell of Bow,270/why ever/seesaw,315/nothing/roundabout} {
    \draw [black] (0,0) -- (\i:3cm);
    \path [decorate, decoration={text along path, text=\j, text align=center}] (\i:27.5mm) arc (\i:{\i+45}:27.5mm);
    \path [decorate, decoration={text along path, text=\k, text align=center}] (\i:24mm) arc (\i:{\i+45}:24mm);
  }
\end{tikzpicture}
\end{document}

arced text

EDIT

To align the text nicely with different directions, it is probably best to use text effects along path. This is slower, but it makes it possible to align each character vertically. For example:

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
  [
    arc text/.style={%
      decorate,
      decoration={%
        text effects along path,
        text={#1},
        text align=center,
        text effects/.cd,
        text along path,
        characters={anchor=mid},
      }
    }
  ]
  \draw [thick] (0,0) circle (3cm);
  \foreach \i/\j/\k [evaluate=\i as \m using {\i < 180 ? \i+45 : \i }, evaluate=\i as \n using { \i < 180 ? \i : \i+45 } ] in {0/something/tadpole,45/anything/cauldron,90/another/bread soup,135/whatever/rock candy,180/whenever/lollipop,225/whoever/Bell of Bow,270/why ever/seesaw,315/nothing/roundabout} {
    \draw [black] (0,0) -- (\i:3cm);
    \path [arc text/.expanded=\j] (\m:27.5mm) arc (\m:\n:27.5mm);
    \path [arc text/.expanded={\k}] (\m:24mm) arc (\m:\n:24mm);
  }
\end{tikzpicture}
\end{document}

opposite directions

  • Love the text you've used. How can I change the way the text faces? i.e. Text turned inwards so that the upper quadrants are easier to read? – lexxie May 24 '16 at 4:39
  • You'd need to reverse the path of the arc by saying e.g. ({\i+45}:\i:27.5mm). So you probably want to split the \foreach into two else you'd need to test the value of \i within the loop. The text is just run along the path in the direction of that path, whatever the path happens to be. – cfr May 24 '16 at 10:08
  • @lexxie Please see edit. – cfr May 24 '16 at 10:46

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.