Take the 2-minute tour ×

I want to combine the two figures below into one. That is having an arrow with colors going from red at the bottom to blue at the top. Could anyone show me how to do it?

enter image description here

share|improve this question
Could you please check whether Tikz: Shading a path without any filling helps you? –  Claudio Fiandrino Aug 25 at 9:32
Thanks, could we assign colors to specific points on the path? I see only top and bottom color there. –  wererabit Aug 25 at 9:53
I think you can easily do it by changing type of shading; if you look on the pgfmanual there is also a rainbow shading. –  Claudio Fiandrino Aug 25 at 10:01
Please post a Minimum Working Example which produces the output you've posted (since you've already got that far). –  cfr Aug 25 at 12:15

2 Answers 2

up vote 3 down vote accepted

The problem with trying to do a "color-bar" style shading is that in the process of fitting a shading to a path PGF scales a shading so that only the center quarter of the shading is seen (see "Using Shadings" in the manual).

This means that either a color-bar has to be "squidged" into the center quarter of a shading definition, which is a pain to to manually, or the path to be shaded has to be clipped, and scaled manually which can also be a bit of a nuisance.

The following shows one way of specifying a color-bar with a list of named colors (assumed to occupy equal width of the bar) and automatically generate a (more-or-less) appropriate shading:

\documentclass[tikz, border=5]{standalone}
  \pgfutil@for\pgf@tmp:={#3}\do{\advance\pgfutil@tempcnta by1}%
      \advance\pgfutil@tempcntb by1\relax%
  \csname pgfdeclare#2shading\endcsname{#1}{100}\pgf@spec%


\begin{tikzpicture}[colorbar arrow/.style={
  shape=double arrow,
  double arrow head extend=0.125cm, 
  shape border rotate=90, 
  minimum height=5cm,
\node [colorbar arrow=shading1] at (0,0) {};
\node [colorbar arrow=shading2] at (1,0) {};
\node [colorbar arrow=shading3] at (2,0) {};

enter image description here

share|improve this answer

An example with PSTricks. Run it with xelatex


enter image description here

share|improve this answer

Your Answer


