6

I would like to define a group of colors and print the values of those colors without explicitly defining them again.

xcolor Definitions

\definecolor{colora}{cmyk}{0,.5,1,.3}
\definecolor{colorb}{cmyk}{.4,.6,.5,.1}
\definecolor{colorc}{rgb}{1,0,0}
\definecolor{colord}{rgb}{0,0,1}

In reality I am using Percusse's fancy schmancy code from: https://tex.stackexchange.com/a/235759/13552

I would like to create a color chart like that but with the actual values (the hard part) AND the name of the color (the easy part) of the colors.

enter image description here

Code

Code as it is from Percusse. I do not need rgb values, but they are in there for the sake of completeness.

\documentclass{article}
\usepackage{tikz}


\def\appendcolor#1#2#3{%
\csname pgfutil@ifundefined\endcsname{definedcolorsofar}{\def\definedcolorsofar{#1}}{%
\expandafter\def\expandafter\definedcolorsofar\expandafter{\definedcolorsofar,#1}}%
\definecolor{#1}{#2}{#3}%
}

\appendcolor{colora}{cmyk}{0,.5,1,.3}
\appendcolor{colorb}{cmyk}{.4,.6,.5,.1}
\appendcolor{colorc}{rgb}{1,0,0}
\appendcolor{colord}{rgb}{0,0,1}

\begin{document}
\tikz{
\foreach \x[count=\xi] in \definedcolorsofar 
   \node at (0,\xi)[fill=\x, minimum width=2cm, 
           minimum height=1cm,text=white] {\x}; 
}

\end{document}

Bonus Code

Ideally, I could print the cmyk values + percentage of hiding power (opacity).

\documentclass{article}
\usepackage{fontspec}%xelatex
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}


\def\appendcolor#1#2#3{%
\csname pgfutil@ifundefined\endcsname{definedcolorsofar}{\def\definedcolorsofar{#1}}{%
\expandafter\def\expandafter\definedcolorsofar\expandafter{\definedcolorsofar,#1}}%
\definecolor{#1}{#2}{#3}%
}

\appendcolor{colora}{cmyk}{0,.5,1,.3}
\appendcolor{colorb}{cmyk}{.4,.6,.5,.1}
\appendcolor{colorc}{rgb}{1,0,0}
\appendcolor{colord}{rgb}{0,0,1}

\newcommand\printcolors{
    \foreach \x[count=\xi] in \definedcolorsofar {
        \foreach \colorpercent[count=\coli] in {100,85,65,35,15} {
        \pgfmathtruncatemacro\step{\coli - 1}
        \pgfmathsetmacro\nodeselect{ifthenelse(equal(int(\step),0),"firstnode","restnode")}%
        \tikz [firstnode/.style={name=\x},restnode/.style={}] \node [\nodeselect,fill=\x!\colorpercent, minimum width=2cm, minimum height=1cm,text=white,outer sep=0pt, inner sep=0pt] {\colorpercent\%};%
        }%
    \hfill{\x}\par
    }%
}%

\begin{document}
\printcolors{}
\end{document}

enter image description here

4

You can get the values by first extracting any color definition's specs in RGB and converting into whatever color model

\extractcolorspecs{blue!20!red}{\model}{\mycolor}
\convertcolorspec{\model}{\mycolor}{cmyk}\tmp\tmp

will print out

0,0.8,0.6,0.2

and you can use those for whatever reason.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.