4

While working on some graphics in TikZ, I encountered some special need (which I could of course achieve with some image manipulation programs, but I wonder whether there's a (La)TeXy way): I want to change the color of a character within the character (best at the intersection with some lines).

That's what I'm able to achieve (I know it's pretty much nothing):

some output

That's what I want:

special output

If you need a MWE, here's a test object:

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
    \node[color=gray] {A};
    \draw[thin] (2pt,-4pt) circle (3pt);
\end{tikzpicture}

\end{document}
3

I'll put this as an answer, although i'm not sure it's sufficient long enough. As long as you do not want to do this repeatedly with different areas of the letter, you can just clip things in tikz:

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
    \node[color=gray] {A};
    \draw[thin] (2pt,-4pt) circle (3pt);
\end{tikzpicture}
\begin{tikzpicture}
    \node[color=gray] {A};
    \clip (2pt,-4pt) circle (3pt);
    \node[color=blue] {A};
\end{tikzpicture}

\end{document}

The probably better variant would be to define a macro, at least if you want this multiple times (like capitalised chapter beginnings):

\newcommand{\coloredletter}[1]{\tikz{\node[color=gray] at (0, 0) {#1}; \clip (2pt,-4pt) circle (3pt); \node[color=blue] at (0, 0) {#1};}}

\coloredletter{A}
\coloredletter{B}

The result then looks like this:

enter image description here

3

Clipping does what you want.

Code

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
    \node[color=gray] {A};
    \clip(2pt,-4pt) circle[radius=3pt];
    \node[color=blue] {A};
    \draw[thin](2pt,-4pt) circle[radius=3pt];
\end{tikzpicture}

\end{document}

Output

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.