我使用提供的代码这个问题绘制文本螺旋,现在我想用不同的颜色突出显示用逗号分隔的每个块。 有办法实现吗?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\makeatletter
\let\pgf@lib@dec@text@dobox@original=\pgf@lib@dec@text@dobox%
\def\pgf@lib@dec@text@dobox{%
\pgf@lib@dec@text@dobox@original%
\ifpgfdecorationtextalongpathscaletext%
\pgfmathparse{\pgf@lib@dec@text@endscale+(\pgf@lib@dec@text@startscale-\pgf@lib@dec@text@endscale)*\pgfdecoratedremainingdistance/\pgfdecoratedpathlength}%
\setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\box\pgf@lib@dec@text@box}}%
\fi%
}
\newif\ifpgfdecorationtextalongpathscaletext
\def\pgf@lib@dec@text@startscale{1}
\def\pgf@lib@dec@text@endscale{1}
\pgfkeys{/pgf/decoration/.cd,
text path start scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@startscale{#1}%
},
text path end scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@endscale{#1}%
}
}
\begin{document}
\begin{tikzpicture}[
decoration={
reverse path,
text along path,
text path start scale=1.5,
text path end scale=0,
text={Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua,
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur, Excepteur sint occaecat cupidatat non proident, sunt
inculpa qui officia deserunt mollit anim id est laborum}}
]
\draw [decorate]
(0,0)
\foreach \i [evaluate={\r=(\i/2000)^2;}] in {0,5,...,2880}{ -- (\i:\r)};
\useasboundingbox (-2.75,-2.75) rectangle (2.75,2.75);
\end{tikzpicture}
\end{document}
我找不到我想要的图像,但有类似下图的东西,但色块中也应该有文字。我不关心箭头之类的装饰。
答案1
我不确定我是否理解了这个问题,但这与逗号和颜色有关
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\makeatletter
\def\zr{red}
\def\zy{yellow}
\def\zcomma{,}
\let\z\zr
\let\pgf@lib@dec@text@dobox@original=\pgf@lib@dec@text@dobox%
\def\pgf@lib@dec@text@dobox{%
\ifx\zcomma\pgf@lib@dec@text@char
\ifx\z\zr\let\z\zy\else\let\z\zr\fi
\fi
\pgf@lib@dec@text@dobox@original%
\ifpgfdecorationtextalongpathscaletext%
\pgfmathparse{\pgf@lib@dec@text@endscale+(\pgf@lib@dec@text@startscale-\pgf@lib@dec@text@endscale)*\pgfdecoratedremainingdistance/\pgfdecoratedpathlength}%
\setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\fboxsep\z@\colorbox{\z}{\box\pgf@lib@dec@text@box}}}%
\fi%
}
\newif\ifpgfdecorationtextalongpathscaletext
\def\pgf@lib@dec@text@startscale{1}
\def\pgf@lib@dec@text@endscale{1}
\pgfkeys{/pgf/decoration/.cd,
text path start scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@startscale{#1}%
},
text path end scale/.code={%
\pgfdecorationtextalongpathscaletexttrue%
\def\pgf@lib@dec@text@endscale{#1}%
}
}
\begin{document}
\begin{tikzpicture}[
decoration={
reverse path,
text along path,
text path start scale=1.5,
text path end scale=0,
text={Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua,
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur, Excepteur sint occaecat cupidatat non proident, sunt
inculpa qui officia deserunt mollit anim id est laborum}}
]
\draw [decorate]
(0,0)
\foreach \i [evaluate={\r=(\i/2000)^2;}] in {0,5,...,2880}{ -- (\i:\r)};
\useasboundingbox (-2.75,-2.75) rectangle (2.75,2.75);
\end{tikzpicture}
\end{document}
你可以用支柱和一些字距让它变得平滑一些:
\setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\fboxsep\z@
\kern-.7pt\colorbox{\z}{\kern.7pt\strut\box\pgf@lib@dec@text@box\kern.7pt}\kern-.7pt}}%