[Tex/LaTex] How to specify a direct color in a tikz picture

colorgradienttikz-pgf

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:

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
\begin{document}
\begin{figure}[!h]
\begin{tikzpicture}\shade[left color=red,right color=gray]
  (1.211,0.000) rectangle (0.211,1.000);
\end{tikzpicture}
\end{figure}
\end{document}

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.

Best Answer

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.

EDIT

\documentclass[tikz]{standalone}
\tikzset{xcolor/.code args={#1=#2}{
     \definecolor{mytemp}{rgb}{#2}
     \tikzset{#1=mytemp}
  }
}
\begin{document}
\begin{tikzpicture}
\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);  
\end{tikzpicture}
\end{document}

enter image description here

the edited image

enter image description here

Related Question