1

How can this code be modified so that the first few characters (say 3) are colored red?

\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}

example

1 Answer 1

3

I think this is not a good answer ..... But it works.

\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}

The color has to be set for each character.

Result

1
  • 1
    ... text={0123456789}, text effects/.cd, character count=\i, character total=\n, character 1/.style={text={red}}, character 2/.style={text={red}}, character 3/.style={text={red}}, characters={text along path, ... moves the styling out from the data, but still hard-codes the character numbers.
    – Cicada
    Jun 4, 2022 at 13:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .