3

This question came up to me because I didn't want to define a new color in my LaTeX project.

I want to use a very specific color in my tikz drawing. Using Microsoft Paint's Color Picker tool, I get the following information about it:

screenshot

The values I obtained with the tool are shown in the right window inside the screenshot, reading

Hue: 205
Saturation: 67
Lum(?) 123
Red: 165
Green: 96
Blue: 157

So I went over to TeX to try xcolor's color specification:

\documentclass[border=1pt]{standalone}
\usepackage{xcolor}
\begin{document}
\texttt{red!64.7!green!37.64!blue!61.56!} \hfill \fcolorbox{black}{red!64.7!green!37.64!blue!61.56!}{\hspace{2mm}}
\end{document}

xcolor result

(the red color is 165/255=64.7% so this the value I gave to red, same for green and blue).

Looks close, doesn't it?

So I headed over again to Windows Paint to see if color picker gives the same color, as in the first pick, and it turns out that no:

Hue: 169
Saturation: 95
Lum(brightness?) 148
Red: 136
Green: 119
Blue: 196

second trial

If I am not wrong, one can specifty a color using the rgb model, or the hue, saturation,brightness model. Both differ in the cross check I made.

How can I get exactly the same color?

1 Answer 1

6

To use a color by its RGB components directly in TikZ, see https://tex.stackexchange.com/a/343680/38080 and use for example:

\tikz \fill [color={rgb,255:red,165;green,95;blue,157}] (0,0) rectangle (1,1);

Alternatively, you can define a color or use a model directly: RGB is the model with red, blue, and green with range 0...255.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\definecolor{mycolor}{RGB}{165,95,157}
\begin{document}

{\color{mycolor}\vrule width 50pt height 20pt}

(Back to black)

{\color[RGB]{165,95,157}\vrule width 50pt height 20pt}

(Now with Ti\emph{k}Z):

\tikz \fill [color={rgb,255:red,165;green,95;blue,157}] (0,0) rectangle (1,1);

\end{document}

Here is the result, with a bit of the color picker window: enter image description here

You can find a list of color-changing command in section 2.6 of the manual:

enter image description here

Your ! command is a mix, used to blend colors; with

red!64.7!green!37.64!blue!61.56!

you are mixing 64.7% of red with green, then mix the 37.64% of the result with blue, and then mix the 61.56% of the result with white... See the manual at page 33 (thanks Steven B. Segletes! I got that the other way around) :

enter image description here

which is useful when you want to make gradients or color-coded thing, given that it works with whatever color, like mycolor1!50!mycolor2.

6
  • Hmm.. Good to know! So what is the correct use of the red!_!green!_!blue!_!?
    – tush
    Commented May 8, 2021 at 19:00
  • Still, is it possible to use the red!_!green!_!blue!_! to completely specify an rgb combination?
    – tush
    Commented May 8, 2021 at 19:10
  • @tush, maybe, but you have to carry out the weights, because the mix is made progressively; so red!50!blue!50!green will have 25% red, 25% blue, and 50% green.
    – Rmano
    Commented May 8, 2021 at 19:12
  • I understand. I will take the time in the next few days to make the calculation. If it is possible, and if I succeed, I will write down an answer here. Thanks for your insight.
    – tush
    Commented May 8, 2021 at 19:14
  • 1
    Based on your explanation, red!80!green would be 80% green. But methinks it is 80% red. Thus, to my way of thinking, red!50!blue!75!green is 50% red, 37.5% blue and 12.5% green Commented May 8, 2021 at 22:53

You must log in to answer this question.

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