4

How can be colored a line/path in tikz? i.e. green before the 5 and red after? enter image description here

I have seen a option with

\usetikzlibrary{decorations.markings}

but this seems too much complex to the task (even though I couldn't do it). But is the only way?

\begin{tikzpicture}[scale=0.5]
    \draw[ blue] (-6,0)-- (9,0); 
    \foreach \x in {0,5} {
        \draw (\x,0.5) -- (\x,-0.5) node[below] {\x};
    }
    \draw[] (5,0) circle (0.5);
\end{tikzpicture}

riccs_0x
  • 1,087
  • 1
    https://tex.stackexchange.com/a/321203/197451 -- https://tex.stackexchange.com/a/488017/197451 – js bibra Dec 14 '20 at 01:12
  • 2
    You can always draw it as two separate lines, or if that is not convinient draw over the desired alternate color. Only the last color will show. – Peter Grill Dec 14 '20 at 01:53

1 Answers1

3

I think edge[] is what you are looking for:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=0.5]
    \draw[ blue] (-6,0)-- +(0:11cm) edge[green] +(0:6cm) edge[red] (9,0); 
    \foreach \x in {0,5} {
        \draw (\x,0.5) -- (\x,-0.5) node[below] {\x};
    }
    \draw[] (5,0) circle (0.5);

\end{tikzpicture}

\end{document}

enter image description here

Roland
  • 6,655