我画了一个圆圈,上面有一些沿着曲线的文字,如下所示:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{fontspec}
\usetikzlibrary{decorations.text}
\setmainfont{Times New Roman}
\begin{document}
\fontspec{Times New Roman}
\addfontfeature{LetterSpace=50.0}
\begin{tikzpicture}
\draw [
thick,
postaction={
decorate,
decoration={
raise=-4.5ex,
text along path,
reverse path,
text align={left},
text={A bunch of text}
}
},
] (0,0) circle (3.5cm);
\end{tikzpicture}
\end{document}
显然,我想要的是扩大字母之间的间距,但 TiKZ 似乎将每个单词视为一个字母,并增加了单词之间的间距。在这种情况下,有没有办法获得字母间距?如果有,那是什么?
答案1
decoration
该键有两个文本对齐选项,TikZ
允许将文本调整到路径。fit to path
通过调整字符之间的间距来装饰路径。fit to path stretching spaces
通过增加单词之间的间距来装饰路径。
MWE 提供了这两个选项的说明,第一个示例使用fit to path
,第二个示例使用fit to path stretching spaces
。第三个示例演示了如何沿路径格式化文本。有关详细信息,请参阅 MWE 中的注释。
这是输出:
这是 MWE,必须使用XeLaTex
或编译,LuaLaTex
因为fontspec
已加载才能使用Time New Roman
字体:
% !TeX program = xelatex
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{fontspec}
\usetikzlibrary{decorations.text}
\setmainfont{Times New Roman}
\begin{document}
\fontspec{Times New Roman}
% \addfontfeature{LetterSpace=50.0} <- Not applicable here
\begin{tikzpicture}
\draw [ rotate=145, % <- add rotation to get "A" at the top
thick,
postaction={
decorate,
decoration={
raise=-4.5ex,
text along path,
reverse path,
text align=fit to path, % <- spaces added between each character
text={ {\qquad} %<- Creates space between the first and last letter
A bunch of text
}
}
},
] (0,0) circle (3.5cm);
\end{tikzpicture}%
\begin{tikzpicture}
\draw [ rotate=180,
thick,
postaction={
decorate,
decoration={
raise=-4.5ex,
text along path,
reverse path,
text align=fit to path stretching spaces, % <- spaces between words increased
text={ {\qquad}
A bunch of text
}
}
},
] (0,0) circle (3.5cm);
\end{tikzpicture}%
\begin{tikzpicture}
\draw [ rotate=180,
thick,
postaction={
decorate,
decoration={
raise=-4.5ex,
text along path,
reverse path,
text align=fit to path,
text={ {\qquad} % <- enclose macro in {}
|\Large\color{blue}| % <- Define the formatting of the text enclosed by |
A bunch
|\LARGE\bfseries\color{red}| % <- Change the formatting
of text
}
}
},
] (0,0) circle (3.5cm);
\end{tikzpicture}
\end{document}