
Ich erstelle eine benutzerdefinierte Form und muss einen Text darin einfügen. Das Problem ist jedoch, dass mein Text nicht auf die Länge des dekorierten Pfads passt. Ich brauche also eine Möglichkeit, Text automatisch auf zwei oder drei Pfade aufzuteilen.
Das hier ist also meine Form und die Linien darin sind die Stellen, an denen ich meinen Text einfügen möchte:
Ich erzeuge diese Form mit dem folgenden Code:
\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}
Ich habe vor, diesen Zeilen Text hinzuzufügen, indem ich die Pfaddekoration verwende:
\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);
Wenn der Text jedoch lang ist, passt er nicht in den vorgesehenen Platz.
Ich muss also einen Weg finden, den bereitgestellten Platz zu berechnen und den Text dann auf die verschiedenen Pfade aufzuteilen. Irgendwelche Vorschläge?
Antwort1
Sie können einen einzelnen Pfad (mit mehreren Segmenten) verwenden.(Beachten Sie den „Fehler“: TikZ verwendet jedes Segment in umgekehrter Reihenfolge …)
\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}
Hier eine Komplettlösung ohne reverse path
Option (um den „Fehler“ zu vermeiden) und ohne (0,0)
(um die Form in den Begrenzungsrahmen einzupassen).
\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}