1

Background

I wish to create a LaTeX version of a color palette similar to the one found here: https://codepen.io/devi8/pen/nJMGZR. It looks like this:

enter image description here

I have managed to find code to build on, but I am stuck on two issues:

  1. How do I use CMYK instead of RGB in the MWE?
  2. How can I divide each box into two boxes and add a shadow border to each?

Minimal Working Example (MWE)

\documentclass{article}
\usepackage{xcolor,stackengine}

\newcommand\palbox[2]{{\sffamily\fboxsep=10pt\relax\fboxrule=0pt\relax\footnotesize% \fcolorbox{gray!50}{gray!10}{% \stackengine{8pt}{% \colorbox[RGB]{#1}{\rule{60pt}{0pt}\rule{0pt}{60pt}}% }{% \color{black!60}\stackengine{6pt}{##2}{\saycolors{#1}}{U}{l}{F}{F}{S}% }{U}{l}{F}{F}{S}% }% }}

\newcommand\saycolors[1]{\saycolorsaux#1\relax} \def\saycolorsaux#1 #2 #3\relax{R:#1 G:#2 B:#3}

\begin{document} \palbox{1 103 143}{01678f}\quad \palbox{221 109 16}{dd6d10}\quad \palbox{18 54 69}{123645}\quad \palbox{120 121 124}{78797c} \end{document}

Current output

enter image description here

Desired output

Two CMYK colors next to each other in one box with shadow.

kexxcream
  • 2,815

1 Answers1

2

This isn't a solution based on your code but based on tcolorbox. I'm not an expert in color systems, so I don't know if CMYK works properly here.

EDIT: Color name and CMYK code are now separate. tcbraster to put swatches in columns and rows.

enter image description here

\documentclass{article}
\usepackage{helvet}
\usepackage{array,tabularx,colortbl}
\usepackage[most]{tcolorbox}

\newcommand{\swatch}[5]{% \definecolor{c1}{cmyk}{#1}% \definecolor{c2}{cmyk}{#3}% \begin{tcolorbox}[ enhanced, frame hidden, width=21ex, clip upper, fontupper=\color{gray}, colback=white, fuzzy shadow={0mm}{0pt}{-.5pt}{1pt}{black!60!white}, tabularx={XX} ] \cellcolor{c1} & \cellcolor{c2} \[4ex] \multicolumn{2}{l}{\textsf{#5}\rule{0pt}{3ex}} \ {\tiny\textsf{#2}} & {\tiny\textsf{#4}} \end{tcolorbox}% }

\begin{document} \begin{tcbraster}[raster columns=2,raster force size=false] \swatch{.61,.34,0,.07}{blue1}{.66,.38,0,.14}{blue2}{Blue Jeans} \swatch{0,.19,.67,0}{yellow1}{0,.24,.73,.04}{yellow2}{Sunflower} \swatch{.25,0,.51,.17}{green1}{.27,0,.58,.24}{green2}{Grass} \swatch{0,.64,.57,.07}{red1}{0,.69,.62,.15}{red2}{Grapefruit} \end{tcbraster} \end{document}

  • This looks fantastic, is there a. way to get the two swatches next to each other without a line break? And is it possible to define the color and the text separately? – kexxcream May 08 '22 at 08:04
  • 1
    @kexxcream I extended my answer –  May 08 '22 at 08:44
  • Great, one final issues. I'm using CMYK for in the \documentclass and the color are not rendered good. Is it possible to force \definecolor to use RGB? – kexxcream May 08 '22 at 11:34
  • Solved the above issue thanks to https://tex.stackexchange.com/questions/537188/can-there-be-rgb-and-cmyk-in-a-document-at-the-same-time. The solution was to use \selectcolormodel{RGB} to change color model. – kexxcream May 08 '22 at 11:44