我想要一些用文字装饰的圆圈,其周长自动等于文字的长度。
这有点像我的 MWE,但不需要通过反复试验手动计算半径。
\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}
答案1
将文本放入新的长度寄存器,例如,
\newlength\circl
\settowidth\circl{Herr Prof.\ Paulinho van Duck duck duck~}
这应该是圆的周长,然后进行计算。要从周长得到半径,r = circumference/2pi
,或者这样说radius=.1591549\circl
,其中.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}