3

If I draw a line as follows:

\documentclass[article]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc,shapes,arrows,snakes,shapes.geometric,patterns,fadings}
\begin{document}
\begin{tikzpicture}
\draw[very thick](0,0)--(1,0);

How can I draw the line so that the line starts as red but then fades into blue, I have tried

\documentclass[article]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc,shapes,arrows,snakes,shapes.geometric,patterns,fadings}
\begin{document}
\begin{tikzpicture}
\draw[very thick,top color=red,bottom color=blue](0,0)--(1,0);

but it does not seem to do anything, any advice?

  • 1
    Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Nov 7 '13 at 19:59
  • 1
    That does not work. You can only stroke a path in one color. The fading/shading applies only to the filled form of a path (in your case, that is a zero-size area). However, TeX.sx has some answers that may help you: How to draw an arrow with two colors? vs Path following color gradient in TikZ show different forms of shading/fading. In your simple case you could do \path[top color=red, bottom color=blue] (0,+-\pgflinewidth) rectangle (1,+\pgflinewidth);, i.e. for straight lines, you can mimic it. – Qrrbrbirlbel Nov 7 '13 at 20:03
  • 1
    The suggested link seems to be very complicated for such a simple concept – KatyB Nov 7 '13 at 20:20

Browse other questions tagged or ask your own question.