[Tex/LaTex] How to specify a fill color in RGB format in a node in tikzpicture

colorrounded-cornerstikz-pgf

I am just trying to get a rounded corner box with some text in it. The text color will be white and the box will be filled with a particular color.

The preamble includes:

\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
decorations.pathreplacing,decorations.pathmorphing,shapes,%
matrix,shapes.symbols,plotmarks,decorations.markings,shadows}

The code I have used is:

\begin{tikzpicture}
\node[drop shadow,fill=black,draw,rounded corners]
{\textcolor{white}{TEST}};
\end{tikzpicture}

How can I specify an arbitrary color (RGB values in a range of 0-255) in the fill option?

Also, am I using too advanced a tool (tikz) to do something simple (draw a rounded corner rectangle filled with a color and text of some other color)?

Best Answer

In answer to your first question - mixing colours in (say) RGB format - you could use the notation similar to that specified in the xcolor package documentation, since TikZ recognizes this. For example, mixing/sharing proportions of black green is obtained using

\node[...,fill=black,...]
\node[...,fill=black!60!green,...]
\node[...,fill=black!30!green,...]
\node[...,fill=green,...]

and displays

Nodes with different colour fills (sharing between black and green)

Or, if you're interested in mixing certain quantities of RGB colours, you can use a part-wise mix as follows:

\node[...,fill={rgb:red,4;green,2;yellow,1},...]
\node[...,fill={rgb:red,1;green,2;blue,5},...]
\node[...,fill={rgb:orange,1;yellow,2;pink,5},...]
\node[...,fill={rgb:black,1;white,2},...]

which outputs

Part-wise mix of colours

For answering your second question - dealing with boxes - you can use the fancybox package or even PStricks. Here is an example using the latter:

\documentclass{article}
\usepackage{pstricks}
\begin{document}
\begin{pspicture}(5,5)
  \psset{fillstyle=solid,framearc=.3}
  \psframebox[fillcolor=red]{\textcolor{white}{TEST}}
  \psframebox[fillcolor=green!50!red]{\textcolor{white}{TEST}}
  \psframebox[fillcolor=black!50]{\textcolor{white}{TEST}}
  \psframebox[fillcolor={rgb:red,1;green,2;blue,3}]{\textcolor{white}{TEST}}
\end{pspicture}
\end{document}​

PStricks rounded/coloured boxes