使用 decorations.text 装饰路径的文本换行符

使用 decorations.text 装饰路径的文本换行符

是否可以在装饰路径的文本中使用换行符?考虑以下 MWE:

% Circular arrows with text
% Author: Tom Bombadil
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.text}
\newcommand*{\mytextstyle}{\sffamily\Large\bfseries\color{black!85}}
\newcommand{\arcarrow}[8]{%
% inner radius, middle radius, outer radius, start angle,
% end angle, tip protusion angle, options, text
  \pgfmathsetmacro{\rin}{#1}
  \pgfmathsetmacro{\rmid}{#2}
  \pgfmathsetmacro{\rout}{#3}
  \pgfmathsetmacro{\astart}{#4}
  \pgfmathsetmacro{\aend}{#5}
  \pgfmathsetmacro{\atip}{#6}
  \fill[#7] (\astart:\rin) arc (\astart:\aend:\rin)
       -- (\aend+\atip:\rmid) -- (\aend:\rout) arc (\aend:\astart:\rout)
       -- (\astart+\atip:\rmid) -- cycle;
  \path[font = \sffamily, decoration = {text along path, text = {|\mytextstyle|#8},
    text align = {align = center}, raise = -0.5ex}, decorate]
    (\astart+\atip:\rmid) arc (\astart+\atip:\aend+\atip:\rmid);
}

\begin{document}
\begin{tikzpicture}
  \fill[even odd rule,red!30] circle (3.8) circle (3.2);
  \foreach \x in {0,60,...,300} {
    \arcarrow{3}{3.5}{4}{\x+20}{\x+70}{5}{red,
      draw = red!50!black, very thick}{a very long text that wants to be split into multiple lines \x}
  }
\end{tikzpicture}
\end{document}

使用 '\\' 无法编译。我看了http://tug.ctan.org/info/visualtikz/VisualTikZ.pdf但是,从本质上来说,这似乎是不可能的。有什么想法吗?

答案1

这?

在此处输入图片描述

% Circular arrows with text
% Author: Tom Bombadil
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.text}
\newcommand*{\mytextstyle}{\sffamily\Large\bfseries\color{black!85}}
\newcommand{\arcarrow}[8]{%
% inner radius, middle radius, outer radius, start angle,
% end angle, tip protusion angle, options, text
  \pgfmathsetmacro{\rin}{#1}
  \pgfmathsetmacro{\rmid}{#2}
  \pgfmathsetmacro{\rout}{#3}
  \pgfmathsetmacro{\astart}{#4}
  \pgfmathsetmacro{\aend}{#5}
  \pgfmathsetmacro{\atip}{#6}
  \fill[#7] (\astart:\rin) arc (\astart:\aend:\rin)
       -- (\aend+\atip:\rmid) -- (\aend:\rout) arc (\aend:\astart:\rout)
       -- (\astart+\atip:\rmid) -- cycle;
  \path[font = \sffamily, decoration = {text along path, text = {|\mytextstyle|#8},
    text align = {align = center}, raise = -0.5ex}, decorate]
    (\astart+\atip:\rmid) arc (\astart+\atip:\aend+\atip:\rmid);
}

\begin{document}
\begin{tikzpicture}
  \fill[even odd rule,red!30] circle (3.8) circle (3.2);
  \foreach \x in {0,60,...,300} {
    \arcarrow{3}{3.5}{4}{\x+20}{\x+70}{5}{red,
      draw = red!50!black, very thick}{%
{\footnotesize\begin{tabular}{@{}c@{}}
a very long text\\
that wants to be\\
split into multiple\\
lines
\end{tabular}}
\x}
  }
\end{tikzpicture}
\end{document}

答案2

基于使用 tikz 在弯曲箭头内绘制弯曲文本(多行)使用多个后续操作,我最终得到了以下解决方案(可能会有所改进,但可以满足我的需求):

在此处输入图片描述

% Circular arrows with text
% Author: Tom Bombadil
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.text}
\newcommand*{\mytextstyle}{\sffamily\Large\bfseries\color{black!85}}
\newcommand{\arcarrow}[8]{%
% inner radius, middle radius, outer radius, start angle,
% end angle, tip protusion angle, options, text
  \pgfmathsetmacro{\rin}{#1}
  \pgfmathsetmacro{\rmid}{#2}
  \pgfmathsetmacro{\rout}{#3}
  \pgfmathsetmacro{\astart}{#4}
  \pgfmathsetmacro{\aend}{#5}
  \pgfmathsetmacro{\atip}{#6}
  \fill[#7] (\astart:\rin) arc (\astart:\aend:\rin)
       -- (\aend+\atip:\rmid) -- (\aend:\rout) arc (\aend:\astart:\rout)
       -- (\astart+\atip:\rmid) -- cycle;
  \foreach \x/\y in #8 
  {
    \path[{postaction={decoration = {text along path, text align = {align = center}, text={\x}, reverse path, raise=\y ex}, decorate}}] (\astart+\atip:\rmid) arc (\astart+\atip:\aend+\atip:\rmid);
  }
}
\begin{document}
\begin{tikzpicture}
  \fill[even odd rule,red!30] circle (3.8) circle (3.2);
  \foreach \x in {0,60,...,300} {
    \arcarrow{2.75}{3.5}{4}{\x+20}{\x+70}{5}{red,
      draw = red!50!black, very thick}{{a very long text/1.5, that wants to be/-0.5, split into multiple/-2.5, lines/-4.5}}
  }
\end{tikzpicture}
\end{document}

答案3

以下答案使用轮图包,是我写的。

密钥中的文本arc data可以包含\\将文本分割成多行。

此文本以键为中心arc data pos=0.5

箭是用钥匙获得的slices arrow={-0.6}{0}

在此处输入图片描述

\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\fill[red!30,even odd rule] (0,0) circle[radius=3.8] circle[radius=3.2];
\wheelchart[
  arc data=a very long text\\that wants to be\\split into multiple\\lines,
  arc data angle shift=-5,
  arc data expand=f,
  arc data pos=0.5,
  gap polar=5,
  radius={2.8}{4.2},
  slices arrow={-0.6}{0},
  slices style={red,draw=red!50!black,very thick},
  total count=6
]{}
\end{tikzpicture}
\end{document}

相关内容