20

I would like to have some text decorated circles with their circumference automatically equal to the length of the text.

That is something like my MWE but without calculating the radius manually by trial and error.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
    \begin{tikzpicture}
        \path[draw, 
            postaction={decorate,decoration={%
                text={egreg~}, 
                text along path,
                text align=right,
                raise=-10pt,
                }}
            ]
            (0,0) circle [radius=.46em];
        \path[draw, 
            postaction={decorate,decoration={%
                text={David Carlisle~}, 
                text along path,
                text align=right,
                raise=-10pt,
                }}
            ]
            (2,0) circle [radius=1.05em];   
        \path[draw, 
            postaction={decorate,decoration={%
                text={Herr Prof.\ Paulinho van Duck~}, 
                text along path,
                text align=right,
                raise=-10pt,
                }}
            ]
            (1,-2) circle [radius=2.2em];   
    \end{tikzpicture}
\end{document}

enter image description here

  • 9
    oi why is David upside down, I'm getting dizzy – David Carlisle Nov 12 '17 at 10:14
18

Put the text into a new length register, for example,

\newlength\circl
\settowidth\circl{Herr Prof.\ Paulinho van Duck duck duck~}

this should be the circumference of the circle, then do the math. To get the radius from circumference, r = circumference/2pi, or put it like this radius=.1591549\circl, where .1591549 = 1/2pi.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\newlength\circl
\settowidth\circl{Herr Prof.\ Paulinho van Duck duck duck~}
    \begin{tikzpicture}
        \path[draw, 
            postaction={decorate,decoration={%
                text={egreg~}, 
                text along path,
                text align=right,
                raise=-10pt,
                }}
            ]
            (0,0) circle [radius=.46em];
        \path[draw, 
            postaction={decorate,decoration={%
                text={David Carlisle~}, 
                text along path,
                text align=right,
                raise=-10pt,
                }}
            ]
            (2,0) circle [radius=1.05em];   
        \path[draw, 
            postaction={decorate,decoration={%
                text={Herr Prof.\ Paulinho van Duck duck duck~}, 
                text along path,
                text align=right,
                raise=-10pt,
                }}
            ]
            (1,-3) circle [radius=.1591549\circl];   
    \end{tikzpicture}
\end{document}

enter image description here

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.