0

How do you define colors using hsb color parameters? I need a certain hue and want to fiddle with the saturation and the brightness. The xcolor package documentation does not explain how to use \definecolor with the hsb model. In fact, it's more by chance that I managed to use it with rgb, which is RGB in xcolor.

So, what I am trying to do, in short is this

\definecolor{bgsbrown}{RGB}{235,172,59}
\definecolor{bgsdarkbrown}{RGB}{191,124,0}

but using hsb (which apparently doesn't work that way):

\definecolor{bgsbrown}{hsb}{26,196,138}
\definecolor{bgsdarkbrown}{hsb}{26,240,90}

The obvious advantage is that the hue (26) stays the same and I can alter saturation and brightness and have a consistent color model in my document.

Now don't get me wrong, I don't want to use exactly these commands, I just want to know how to use the hsb color model the correct way in LaTeX.

An MWE to play with:

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}

\definecolor{bgsbrown}{RGB}{235,172,59}
\definecolor{bgsdarkbrown}{RGB}{191,124,0}

\definecolor{bgsbrownhsb}{hsb}{26,196,138}
\definecolor{bgsdarkbrownhsb}{hsb}{26,240,90}

\begin{document}
    \begin{tikzpicture}
        \fill [bgsbrown] (0,0) rectangle (1,1);
        \fill [bgsdarkbrown] (1,0) rectangle (2,1);
        \fill [bgsbrownhsb] (0,1) rectangle (1,2);
        \fill [bgsdarkbrownhsb] (1,1) rectangle (2,2);
    \end{tikzpicture}
\end{document}

and the corresponding output:

a fuchsia rectangle on top of a lighter and a darker brown square

Oh, btw, I looked at

defining new color

How to make correct shading with hsb color model?

Alter saturation or brightness of a color

TikZ won't support HSB color model hsb in article document class

Colors in xcolor and color models

but either I didn't understand what they were trying to tell me, or they don't provide the solution to the way how to use hsb color parameters.

EDIT: PaulGaborit's comment lead to

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}

\definecolor{fakebrownhsb}[rgb]{HSB}{26,196,138}
\definecolor{fakedarkbrownhsb}[rgb]{HSB}{26,240,90}

\definecolor{bgsbrownhsb}{HSB}{26,196,138}
\definecolor{bgsdarkbrownhsb}{HSB}{26,240,90}

\definecolor{bgsbrown}{RGB}{235,172,59}
\definecolor{bgsdarkbrown}{RGB}{191,124,0}

\begin{document}

    \begin{tikzpicture}[scale=3]
        \fill [fakebrownhsb] (0,2) rectangle (1,3);
        \fill [fakedarkbrownhsb] (1,2) rectangle (2,3);
        \fill [bgsbrownhsb] (0,1) rectangle (1,2);
        \fill [bgsdarkbrownhsb] (1,1) rectangle (2,2);
        \fill [bgsbrown] (0,0) rectangle (1,1);
        \fill [bgsdarkbrown] (1,0) rectangle (2,1);
    \end{tikzpicture}
\end{document}

(I changed the order of the definitions and the order of the drawn objects in the source so they match the tikzpicture from top to bottom)

with output

enter image description here

  • I use XeLaTeX to compile, if that's of any concern ;) – thymaro May 23 '18 at 12:23
  • Look for table 3, p.10, xcolor documentation: HSB uses values between 0 and 240 (hsb uses values between 0 and 1). – Paul Gaborit May 23 '18 at 12:26
  • 2
    Note: to avoid conversion by the PDF viewer and use only rgb color, you can use the optional parameter: \definecolor{bgsbrownhsb}[rgb]{HSB}{26,196,138}. – Paul Gaborit May 23 '18 at 12:27
  • @PaulGaborit huh... the problem is a different one, then. I replaced hsb by HSB and the mwe works. My main document still won't compile, but it seems tcolorbox is being picky about color models. ! Package pgf Error: Unsupported color model 'hsb'. Sorry. Is there another way of staying with one hue and adjusting saturation and brightness, when using PGF? That would answer the original question, too. – thymaro May 23 '18 at 12:46
  • Try the solution in my second comment... – Paul Gaborit May 23 '18 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.