我制作了一个自定义形状,需要在里面放一段文字。但问题是我的文字不适合装饰路径的长度。因此,我需要一种方法来自动将文字划分为两条或三条路径。
所以,这是我的形状,里面的线条是我想要放置文本的地方:
我使用以下代码生成此形状:
\begin{tikzpicture}
% shape
\draw (0,0) ++ (45:3) arc (45:135:3);
\draw (0,0) ++ (45:5) arc (45:135:5);
\draw (45:3) -- (45:5);
\draw (135:3) -- (135:5);
%lines for text
\draw (0,0) ++ (50:3.5) arc (50:130:3.5);
\draw (0,0) ++ (50:4) arc (50:130:4);
\draw (0,0) ++ (50:4.5) arc (50:130:4.5);
\end{tikzpicture}
我计划使用路径修饰将文本添加到此行:
\path[
postaction={
decorate,
decoration={
text along path,
reverse path=true,
text={very long long text, which don't fit the shape boundaries}
}
}
] (0,0) ++ (50:4.5) arc (50:130:4.5);
但如果文本很长,它就不适合提供的空间。
因此,我必须找到一种方法来计算提供的空间,然后将文本划分到几条路径之间。有什么建议吗?
答案1
您可以使用单一路径(包含多段)。(请注意“错误”:TikZ 以相反的顺序使用每个段......)
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
% shape
\draw (0,0) ++ (45:3) arc (45:135:3);
\draw (0,0) ++ (45:5) arc (45:135:5);
\draw (45:3) -- (45:5);
\draw (135:3) -- (135:5);
%lines for text
\draw[blue] (0,0) ++ (50:3.5) arc (50:130:3.5);
\draw (0,0) ++ (50:4) arc (50:130:4);
\draw (0,0) ++ (50:4.5) arc (50:130:4.5);
% text along path
\path[
postaction={
decorate,
decoration={
text along path,
reverse path=true,
text={Very long long text, which don't fit the shape boundaries
and so on. Very long long text... Very long text...}
}
}
]
(0,0) ++ (50:3.5) arc (50:130:3.5)
(0,0) ++ (50:4) arc (50:130:4)
(0,0) ++ (50:4.5) arc (50:130:4.5);
\end{tikzpicture}
\end{document}
这里有一个完整的解决方案,没有reverse path
选项(以避免“错误”)并且没有(0,0)
(使形状适合边界框)。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
% shape
\draw (45:3) arc (45:135:3)
-- (135:5) arc (135:45:5)
-- cycle;
% lines for text
\draw
(50:3.5) arc (50:130:3.5)
(50:4) arc (50:130:4)
(50:4.5) arc (50:130:4.5);
% text along path
\path[postaction={decorate,decoration={
text along path,
text={Very long long text, which don't fit the shape boundaries
and so on. Very long long text... Very long text...}
}}]
(130:4.5) arc (130:50:4.5)
(130:4) arc (130:50:4)
(130:3.5) arc (130:50:3.5);
\end{tikzpicture}
\end{document}