I have some troubles with text alignment along path in tikz. I made custom shape and wrote text along path inside it in the following way:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
% shape
\draw (70:3) arc (70:110:3)
-- (110:5) arc (110:70:5)
-- cycle;
\path[
postaction={
decorate,
decoration={
text along path,
text align = center,
text={Gershon Daly Bonifacy Yaw}
}
}
]
(105:4.5) arc (105:75:4.5)
(105:4.0) arc (105:75:4.0)
(105:3.5) arc (105:75:3.5);
\end{tikzpicture}
\end{document}
Result is pretty fine, but there are small issues. This is output without central alignment:
and this is with central alignment:
My issue is that I want a correct line breaking (don't break lines in the middle of the word) and alignment relative to the center line of the shape, not the path.
I know that when rendering text along path every letter is wrapping in different \hbox
and turn to the correct degree separately.
Any suggestions?
UPDATE:
In this answer path is decorated only in case if text fits the path. May be there are similar approach to decorate path only with fitted text and left rest of the text to the other paths?
UPDATE 2:
I can hide text if the text don't fit path redefining left indent state as stated in mentioned answer above:
\makeatletter
\pgfkeys{
/pgf/decoration/omit long text/.code={%
\expandafter\def\csname pgf@decorate@@text along path@left indent@options\expandafter\expandafter\expandafter\endcsname\expandafter\expandafter\expandafter{\csname pgf@decorate@@text along path@left indent@options\endcsname,switch if less than=\pgf@lib@dec@text@width to final}%
},
}
\makeatother
My idea is to not only skip typesetting text (switch to final state), but also set some flag that mean that text is not typeset, so I can decrease text length and call decoration again.