是否可以计算 TikZ 编写的文本的长度?
我想将单词放入圆圈内。但有时单词对于圆圈来说太长了。所以我的想法是计算文本的长度,如果文本太长,则调整字体大小。
答案1
也许圆形fitbox
(来自tcolorbox
)可以帮助您。您只需定义框大小并将tcolorbox
文本放入其中。只有大于提供的空间的文本才会缩小。
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\newtcboxfit{\myfitbox}{%
width = 3cm,
square,
circular arc,
halign = center,
valign = center,
nobeforeafter
}
\begin{document}
\myfitbox{This is a long text inside a circular tcolorbox}
%
\myfitbox{This is an ever longer text inside a circular tcolorbox}
%
\myfitbox{This is a much more longer, longer and longer text inside a circular tcolorbox}
%
\myfitbox{This is a much more longer, longer and longer text inside a circular tcolorbox. This is a much more longer, longer and longer text inside a circular tcolorbox}
\end{document}