沿路径设置文本的前几个字符的样式

沿路径设置文本的前几个字符的样式

如何修改此代码,使得前几个字符(比如 3 个)变成红色?

\documentclass[tikz]{standalone}
\begin{document}
\usetikzlibrary{decorations.text,calc,math}
\begin{tikzpicture}[
    scale=10,
    decoration={
        text effects along path,
        text={0123456789},
        text effects/.cd,
        character count=\i, character total=\n,
        characters={text along path,
                    evaluate={\c=(\n-\i)+1;},
                    scale=10*\c/\n,
        }
        }
    ]
    \draw[decorate]
          plot (0,0) -- (1,0);
\end{tikzpicture}

\end{document}

例子

答案1

我认为这不是一个好的答案.....但它有效。

\documentclass[tikz]{standalone}
\usepackage{xcolor}
\begin{document}
\usetikzlibrary{decorations.text,calc,math}
\begin{tikzpicture}[
    scale=10,
    decoration={
        text effects along path,
        text={{\color{red}0}{\color{red}1}{\color{red}2}3456789},
        text effects/.cd,
        character count=\i, character total=\n,
        characters={text along path,
                    evaluate={\c=(\n-\i)+1;},
                    scale=10*\c/\n,
        }
        }
    ]
    \draw[decorate]
          plot (0,0) -- (1,0);
\end{tikzpicture}

\end{document}

必须为每个字符设置颜色。

结果

相关内容