8

I am trying to define an rgb color. More specifically I want to create this color

enter image description here

which in rgb mode it's (98,190,177).

I tried to define this color using the following code

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
 \definecolor{tank}{rgb}{0.098,0.190,0.177}
 %\definecolor{tank}{rgb}{98,190,177}
 \begin{tikzpicture}
  \coordinate (tank) at (0,0);
  \draw[red, fill=tank] (-2,0.5)--(-0.5,1)--(0.5,1)--(2,0.5)--(2,-0.5)--(0.5,-1)--(-0.5,-1)--(-2,-0.5)--cycle;
 \end{tikzpicture}
\end{document}

but the output is totally different from what I am trying to achieve

enter image description here

I also tried to use \definecolor{tank}{rgb}{98,190,177} but I get no color at all. How to properly define an rgb color?

5
  • 3
    You want \definecolor{tank}{RGB}{98,190,177}, note the uppercase.
    – egreg
    Commented Aug 30, 2014 at 11:15
  • 2
    or rgb, but with proper scaling of your values, dividing by 255, rather than 1000 as you did in your MWE.
    – greyshade
    Commented Aug 30, 2014 at 11:18
  • @egreg: Wow!!! Thank you very much! I didn't know about that!Would you mind posting an answer? Thank's again!
    – Thanos
    Commented Aug 30, 2014 at 11:18
  • @greyshade : Thank you very much! I didn't know about that either! Why 255?
    – Thanos
    Commented Aug 30, 2014 at 11:19
  • 1
    @Thanos see my answer - 255 is the maximum representable by one byte which is what RGB allocates to represent each base colour's value.
    – greyshade
    Commented Aug 30, 2014 at 11:26

2 Answers 2

8

The colors in the screenshot are specified as

  • HSV: (172, 48, 75) ∈ [0..360] × [0..100]2
  • RGB: (98, 190, 177) ∈ [0..255]3 (three bytes)
  • HTML: 0x62beb1 ∈ [0x0..0xFFFFFF] (three bytes also RGB values)

Package xcolor supports RGB and HTML directly and HSV is indirectly supported via Hsb, where the saturation and brightness are given in range [0..1].

Package color only supports the basic color models such as rgb:

  • rgb: (98/255, 190/255, 177/255) ∈ [0..1]3 (three bytes)

Because of the different range, the values needs to be calculated first.

\documentclass{article}
\usepackage{xcolor}

\definecolor{A}{Hsb}{172,.48,.75}% xcolor
\definecolor{B}{RGB}{98,190,177}% xcolor
\definecolor{C}{HTML}{62BEB1}% xcolor
\definecolor{D}{rgb}{.3843,.7451,.6941}% color, xcolor
% (r, g, b) = (R/255, G/255, B/255)

\begin{document}
\newcommand*{\test}[1]{%
  \textcolor{#1}{\rule{10mm}{10mm}}%
}
\test{A}
\test{B}
\test{C}
\test{D}
\end{document}

Result

7

In RGB mode colours are defined by one byte for each of the colours red, green and blue - hence RGB. The maximum mavlue representable by a byte (i.e. eight bit) is 2^8 - 1 = 255.

Specifying RGB colours may be done in two ways:

\definecolor{tank}{RGB}{98,190,177}
\definecolor{tank}{rgb}{0.3843,0.7451,0.6941}

where the first (with uppercase RGB in the definition) specifies the value of the colour byte, while the second (with lowercase rgb) specifies a percentage - i.e. the value used in the first divided by the maximum value 255.

You must log in to answer this question.

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