I want to model gradients in TikZ for a paper covering color gradients. These are rather special, so a cannot rely on a TikZ shade alone. Thus, I want to model the gradient using consecutive TikZ shaded rectangles, like this:

\begin{tikzpicture}\shade[left color=red,right color=gray]
  (1.211,0.000) rectangle (0.211,1.000);

However, instead of red and blue I need an RGB color triplet as common in HTML. As per xcolor manual 2.3.3, I figured

\shade[left color=rgb,300:red,51;green,41;blue,5,right color=rgb,300:red,50;green,38;blue,0]

might do the job, but I get ! Package xcolor Error: Undefined color `rgb'.

It is feasibe but really awkward to pregenerate all the colors I need. Is it possible to use xcolor direct colors in a TikZ shade? all the examples I came across either use definecolor (even for HTML colors) or named colors.

Any pointers are appreciated.

1 Answer 1


It is not so difficult to create shortcuts for such recurring commands. And you can create and recreate the same color, here is a quick mock-up; you can get the setting you are trying push rgb syntax to and read off the argument of the assignment and place it to a temporary color name. Then use it for the setting of that key.

I don't know how often you will use this and for what so no promises.


\tikzset{xcolor/.code args={#1=#2}{
\shade[xcolor={left color={0.5,0.7,0.1}},xcolor={right color={0.7,0.4,0.8}}] 
(1.211,0.000) rectangle (0.211,1.000);
\shade[xcolor={right color={0.5,0.7,0.1}},xcolor={left color={0.7,0.4,0.8}}] 
(0.211,0.000) rectangle (-1.211,1.000);  

enter image description here

the edited image

enter image description here

  • Thank you, this looks very promising! (I'll test in a few hours.)
    – Simon Thum
    Commented Aug 20, 2014 at 7:12
  • Thanks, this works. In fact I found putting the extended color spec in braces also works, syntactically, but I fail to get RGB on that path, so I ended going with your solution.
    – Simon Thum
    Commented Aug 20, 2014 at 20:51
  • Or, perhaps not. If looked like it worked but it does not scale as I require. The next parts of the gradient (adjacent tikz shades) do not show up at all. Only one shade seems to work with the trick.
    – Simon Thum
    Commented Aug 21, 2014 at 20:58
  • @SimonThum I don't know what you require so you need to make a case for me. Otherwise it does work.
    – percusse
    Commented Aug 21, 2014 at 21:02
  • It's simple; do an adjacent shaded rect like the first, and try to make it show up. There are no latex errors AFAICT but the second shadeed rectangle does not show up in the PDF.
    – Simon Thum
    Commented Aug 21, 2014 at 21:19

You must log in to answer this question.

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