4

I want to create a page where LaTeX colors are aligned with their names. Somewhat analog to the Overleaf color manual page

enter image description here

Specifically: (1) I want to create a thin black border for each color field, so that low contrast to background colors are separated -- e.g. white.

(2) Then I want to have the color names in typewriter font, without affecting the table column names and ideally by avoiding to add \texttt{...} to each name.

(3) be able to change the colored field size easily.

It is not required to be structured as a Table. Practical Readability is the goal! I saw that the xcolor manual does this somehow by creating columns. But I couldn't understand the mechanism or reproduce this.

My best accomplishment was this:

Code is below

\documentclass{scrartcl}

\usepackage[table,dvipsnames,x11names]{xcolor}  % colors with names
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\texttt{
\begin{tabular}{ccc}
  \textbf{Color}                                   & \textbf{Name} & \textbf{xcolor option}\\
\midrule
  \textcolor{black}{\rule{.1\textwidth}{12pt}}     & black    &  \\
  \textcolor{darkgray}{\rule{.1\textwidth}{12pt}}  & darkgray &  \\
  \textcolor{gray}{\rule{.1\textwidth}{12pt}}      & gray     &  \\
  \textcolor{Cerulean}{\rule{.1\textwidth}{12pt}}  & Cerulean & divpsnames \\
  \textcolor{lightgray}{\rule{.1\textwidth}{12pt}} & lightgray&  \\
  \textcolor{Ivory1}{\rule{.1\textwidth}{12pt}}    & Ivory1   & x11names \\
  \textcolor{white}{\rule{.1\textwidth}{12pt}}     & white    &  \\
\end{tabular}
}
\caption{Some \LaTeX{} colors}
\end{table}

\end{document}

2 Answers 2

7

You can use collcell. I made other adjustments to the table.

\documentclass{article}

\usepackage[table,dvipsnames,x11names]{xcolor}  % colors with names
\usepackage{booktabs}
\usepackage{collcell}

% the group is in case you use \colorshow elsewhere
\newcommand{\colorshow}[1]{%
  \begingroup\setlength{\fboxsep}{0pt}%
  \fcolorbox{black}{#1}{\hspace{12pt}\vphantom{X}}%
  \endgroup
}

\begin{document}

\begin{table}
\centering

\begin{tabular}{
  @{}
  >{\collectcell\colorshow}c<{\endcollectcell}
  >{\ttfamily}l
  >{\ttfamily}l
  @{}
}
  \multicolumn{1}{@{}c}{\textbf{Color}} & 
  \multicolumn{1}{c}{\textbf{Name}} &
  \multicolumn{1}{c@{}}{\textbf{xcolor option}} \\
\midrule
  black     & black    &  \\
  darkgray  & darkgray &  \\
  gray      & gray     &  \\
  Cerulean  & Cerulean & divpsnames \\
  lightgray & lightgray&  \\
  Ivory1    & Ivory1   & x11names \\
  white     & white    &  \\
\end{tabular}

\caption{Some \LaTeX{} colors}

\end{table}

\end{document}

enter image description here

2
  • Thank you very much. I've already set the answer as solution and rated it up. If you have a minute, please write some comments on how line \multicolumn{1}{@{}c}{\textbf{Color}} & and lines @{} >{\collectcell\colorshow}c<{\endcollectcell} work. All the best!
    – alex
    Sep 19, 2022 at 12:36
  • @alex For \collectcell look at the manual of collcell. For the top row we need to override the alignment in the subsequent entries, so \multicolumn{1}{...}{...} is our friend.
    – egreg
    Sep 19, 2022 at 12:44
2

For later on, if you need it.

Some colours won't have names. For example, in the red-green-blue colour model, where each of the three channels can take 256 values, there are >16m combinations.

On the other hand, in any case, the human eye cannot distinguish that amount of detailed granularity, and many colour values will look the same.

Even stepping through every 56th colour (say), they are barely distinguishable (a lot will depend on renderer and hardware, too).

close colours

Likewise with grayscale.

grayscale

Plus, who would have time to scroll through thousands of pages of output? So it's a nice-to-have, these 16m colours and 256 shades of gray, not an essential for the toolkit.

However, more practically, with a list of (pre-defined) colour names, the corresponding colours can be easily displayed using an expl3 sequence (=list) and iterating through it with a mapping function:

x11 colour names:

x11

MWE

Done in expl3 as a sort of 'starter kit', with intentional room for optimization. The colour swatch width is configurable as a command option, as is the number of colour value steps to skip.

Printing a list of colour names requires, er, a list of colour names, and the x11 predefined names came from the x11nam.def file of xcolor package.

\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{multicol}

\usepackage{xparse}%now in kernel

\ExplSyntaxOn

\int_new:N \l_doccol_red_int
\int_new:N \l_doccol_green_int
\int_new:N \l_doccol_blue_int
\int_new:N \l_doccol_gray_int
\fp_new:N \l_doccol_gray_fp

\int_new:N \l_doccol_step_int
\int_new:N \l_doccol_defaultstep_int
\int_set:Nn \l_doccol_defaultstep_int { 32 }

\tl_new:N \l_doccol_swatch_tl
\tl_new:N \l_doccol_defaultswatch_tl
\tl_set:Nn \l_doccol_defaultswatch_tl { 3em }




\NewDocumentCommand { \showrgb } { 
            O { \int_use:N \l_doccol_defaultstep_int } % size of step, e.g. 32
            O { \tl_use:N \l_doccol_defaultswatch_tl } % width of swatch, e.g. 3em
            } {

        \int_set:Nn \l_doccol_red_int { 0 }
        \int_set:Nn \l_doccol_green_int { 0 }
        \int_set:Nn \l_doccol_blue_int { 0 }
        \int_set:Nn \l_doccol_step_int { #1 }
        \tl_set:Nn \l_doccol_swatch_tl { #2 }
                
        \int_while_do:nn 
                { \l_doccol_red_int < 256 } 
                {%red
        \int_while_do:nn 
                { \l_doccol_green_int < 256 } 
                {%green
        \int_while_do:nn 
                { \l_doccol_blue_int < 256 } 
                {%blue
                        \definecolor{foo}{RGB}{
                            \int_use:N \l_doccol_red_int
                            ,\int_use:N \l_doccol_green_int
                            ,\int_use:N \l_doccol_blue_int
                        }
                            \center
                            \fcolorbox{blue}{foo}{ \makebox [ 
                                                \l_doccol_swatch_tl
                                                ]{
                                    \strut
                                    }}
                            \\
                            \group_begin:
                            \ttfamily
                            \small
                            r
                            \int_use:N \l_doccol_red_int
                            g
                            \int_use:N \l_doccol_green_int
                            b
                            \int_use:N \l_doccol_blue_int
                            \group_end:
                            \tex_par:D

                \int_add:Nn \l_doccol_blue_int { \l_doccol_step_int }

        }%end blue

                \int_set:Nn \l_doccol_blue_int { 0 }

                \int_add:Nn \l_doccol_green_int { \l_doccol_step_int }
                
        }%end green

        \int_set:Nn \l_doccol_green_int { 0 }
        
                \int_add:Nn \l_doccol_red_int { \l_doccol_step_int }


        }%end red
}


\NewDocumentCommand { \showgray } { 
            O { \int_use:N \l_doccol_defaultstep_int } 
            O { \tl_use:N \l_doccol_defaultswatch_tl }
            } {

        \int_set:Nn \l_doccol_gray_int { 0 }
        \int_set:Nn \l_doccol_step_int { #1 }
        \tl_set:Nn \l_doccol_swatch_tl { #2 }
                
        \int_while_do:nn 
                { \l_doccol_gray_int < 256 } 
                {%
                        \fp_set:Nn \l_doccol_gray_fp { \l_doccol_gray_int / 255 }
                        \definecolor{foo}{gray}{
                                    \fp_use:N \l_doccol_gray_fp
                        }
                            \center
                            \fcolorbox{blue}{foo}{ \makebox [ 
                                                \l_doccol_swatch_tl
                                                ]{
                                    \strut
                                    }}
                            \\
                            \group_begin:
                            \ttfamily
                            \small
                            g
                            \int_use:N \l_doccol_gray_int
                            \group_end:
                            \tex_par:D

    
                \int_add:Nn \l_doccol_gray_int { \l_doccol_step_int }

        }%end gray
}



%****************************************************
%*
%****************************************************
        \cs_generate_variant:Nn 
            \seq_gset_split:Nnn 
            { cno }



%****************************************************
%*
%****************************************************
%--------------------
\NewDocumentCommand { \mfsloadaseq } { o m +m } { 
% 1=namespace
% 2=seq name
% 3=data

                \IfNoValueTF { #1 } 
                        { \tl_clear:N \g_fc_namespace_tl } 
                        { \tl_gset:Nn \g_fc_namespace_tl { #1 } }


    \cs_if_free:cT
            { g_doccol \g_fc_namespace_tl #2 _seq }
            { \seq_new:c
                    { g_doccol \g_fc_namespace_tl #2 _seq } 
            }
    \seq_gclear:c 
            { g_doccol \g_fc_namespace_tl #2 _seq } 
    \seq_gset_split:cno 
            { g_doccol \g_fc_namespace_tl #2 _seq } 
            { , } 
            { #3 }

%   \seq_show:c 
%           { g_doccol \g_fc_namespace_tl #2 _seq } 

}


%****************************************************
%*
%****************************************************
%------------------
    \cs_set:Npn \dc_funccolbyname:n #1 { 
    % 1=colour name item from seq
                        \tl_set:Nx \l_tmpa_tl { #1 }
                            \center
                            \group_begin:
                            \fcolorbox{blue} { \tl_use:N \l_tmpa_tl } { \makebox [ 
                                                \l_doccol_swatch_tl
                                                ]{
                                    \strut
                                    }}
                            \\
                            \ttfamily
                            \small
                             \tl_use:N \l_tmpa_tl 
                            \group_end:
                            \tex_par:D

}






%****************************************************
%*
%****************************************************
%--------------------
\NewDocumentCommand { \showaseq }  { 
            O { \int_use:N \l_doccol_defaultstep_int } 
            O { \tl_use:N \l_doccol_defaultswatch_tl }
            O {}
            m
            } { 
% 1=step (not used)
% 2=width
% 3=namespace
% 4=seq name

        \int_set:Nn \l_doccol_step_int { #1 }
        \tl_set:Nn \l_doccol_swatch_tl { #2 }



                \IfNoValueTF { #3 } 
                        { \tl_clear:N \g_fc_namespace_tl } 
                        { \tl_gset:Nn \g_fc_namespace_tl { #3 } }

            \seq_map_function:cN 
                    { g_doccol \g_fc_namespace_tl #4 _seq } 
                    \dc_funccolbyname:n



}


\ExplSyntaxOff


\mfsloadaseq{x11}{
AntiqueWhite1
,AntiqueWhite2
,AntiqueWhite3
,AntiqueWhite4
,Aquamarine1
,Aquamarine2
,Aquamarine3
,Aquamarine4
,Azure1
,Azure2
,Azure3
,Azure4
,Bisque1
,Bisque2
,Bisque3
,Bisque4
,Blue1
,Blue2
,Blue3
,Blue4
,Brown1
,Brown2
,Brown3
,Brown4
,Burlywood1
,Burlywood2
,Burlywood3
,Burlywood4
,CadetBlue1
,CadetBlue2
,CadetBlue3
,CadetBlue4
,Chartreuse1
,Chartreuse2
,Chartreuse3
,Chartreuse4
,Chocolate1
,Chocolate2
,Chocolate3
,Chocolate4
,Coral1
,Coral2
,Coral3
,Coral4
,Cornsilk1
,Cornsilk2
,Cornsilk3
,Cornsilk4
,Cyan1
,Cyan2
,Cyan3
,Cyan4
,DarkGoldenrod1
,DarkGoldenrod2
,DarkGoldenrod3
,DarkGoldenrod4
,DarkOliveGreen1
,DarkOliveGreen2
,DarkOliveGreen3
,DarkOliveGreen4
,DarkOrange1
,DarkOrange2
,DarkOrange3
,DarkOrange4
,DarkOrchid1
,DarkOrchid2
,DarkOrchid3
,DarkOrchid4
,DarkSeaGreen1
,DarkSeaGreen2
,DarkSeaGreen3
,DarkSeaGreen4
,DarkSlateGray1
,DarkSlateGray2
,DarkSlateGray3
,DarkSlateGray4
,DeepPink1
,DeepPink2
,DeepPink3
,DeepPink4
,DeepSkyBlue1
,DeepSkyBlue2
,DeepSkyBlue3
,DeepSkyBlue4
,DodgerBlue1
,DodgerBlue2
,DodgerBlue3
,DodgerBlue4
,Firebrick1
,Firebrick2
,Firebrick3
,Firebrick4
,Gold1
,Gold2
,Gold3
,Gold4
,Goldenrod1
,Goldenrod2
,Goldenrod3
,Goldenrod4
,Green1
,Green2
,Green3
,Green4
,Honeydew1
,Honeydew2
,Honeydew3
,Honeydew4
,HotPink1
,HotPink2
,HotPink3
,HotPink4
,IndianRed1
,IndianRed2
,IndianRed3
,IndianRed4
,Ivory1
,Ivory2
,Ivory3
,Ivory4
,Khaki1
,Khaki2
,Khaki3
,Khaki4
,LavenderBlush1
,LavenderBlush2
,LavenderBlush3
,LavenderBlush4
,LemonChiffon1
,LemonChiffon2
,LemonChiffon3
,LemonChiffon4
,LightBlue1
,LightBlue2
,LightBlue3
,LightBlue4
,LightCyan1
,LightCyan2
,LightCyan3
,LightCyan4
,LightGoldenrod1
,LightGoldenrod2
,LightGoldenrod3
,LightGoldenrod4
,LightPink1
,LightPink2
,LightPink3
,LightPink4
,LightSalmon1
,LightSalmon2
,LightSalmon3
,LightSalmon4
,LightSkyBlue1
,LightSkyBlue2
,LightSkyBlue3
,LightSkyBlue4
,LightSteelBlue1
,LightSteelBlue2
,LightSteelBlue3
,LightSteelBlue4
,LightYellow1
,LightYellow2
,LightYellow3
,LightYellow4
,Magenta1
,Magenta2
,Magenta3
,Magenta4
,Maroon1
,Maroon2
,Maroon3
,Maroon4
,MediumOrchid1
,MediumOrchid2
,MediumOrchid3
,MediumOrchid4
,MediumPurple1
,MediumPurple2
,MediumPurple3
,MediumPurple4
,MistyRose1
,MistyRose2
,MistyRose3
,MistyRose4
,NavajoWhite1
,NavajoWhite2
,NavajoWhite3
,NavajoWhite4
,OliveDrab1
,OliveDrab2
,OliveDrab3
,OliveDrab4
,Orange1
,Orange2
,Orange3
,Orange4
,OrangeRed1
,OrangeRed2
,OrangeRed3
,OrangeRed4
,Orchid1
,Orchid2
,Orchid3
,Orchid4
,PaleGreen1
,PaleGreen2
,PaleGreen3
,PaleGreen4
,PaleTurquoise1
,PaleTurquoise2
,PaleTurquoise3
,PaleTurquoise4
,PaleVioletRed1
,PaleVioletRed2
,PaleVioletRed3
,PaleVioletRed4
,PeachPuff1
,PeachPuff2
,PeachPuff3
,PeachPuff4
,Pink1
,Pink2
,Pink3
,Pink4
,Plum1
,Plum2
,Plum3
,Plum4
,Purple1
,Purple2
,Purple3
,Purple4
,Red1
,Red2
,Red3
,Red4
,RosyBrown1
,RosyBrown2
,RosyBrown3
,RosyBrown4
,RoyalBlue1
,RoyalBlue2
,RoyalBlue3
,RoyalBlue4
,Salmon1
,Salmon2
,Salmon3
,Salmon4
,SeaGreen1
,SeaGreen2
,SeaGreen3
,SeaGreen4
,Seashell1
,Seashell2
,Seashell3
,Seashell4
,Sienna1
,Sienna2
,Sienna3
,Sienna4
,SkyBlue1
,SkyBlue2
,SkyBlue3
,SkyBlue4
,SlateBlue1
,SlateBlue2
,SlateBlue3
,SlateBlue4
,SlateGray1
,SlateGray2
,SlateGray3
,SlateGray4
,Snow1
,Snow2
,Snow3
,Snow4
,SpringGreen1
,SpringGreen2
,SpringGreen3
,SpringGreen4
,SteelBlue1
,SteelBlue2
,SteelBlue3
,SteelBlue4
,Tan1
,Tan2
,Tan3
,Tan4
,Thistle1
,Thistle2
,Thistle3
,Thistle4
,Tomato1
,Tomato2
,Tomato3
,Tomato4
,Turquoise1
,Turquoise2
,Turquoise3
,Turquoise4
,VioletRed1
,VioletRed2
,VioletRed3
,VioletRed4
,Wheat1
,Wheat2
,Wheat3
,Wheat4
,Yellow1
,Yellow2
,Yellow3
,Yellow4
,Gray0
,Green0
,Grey0
,Maroon0
,Purple0
}



\begin{document}
\section{RGB}
\begin{multicols}{5}
\showrgb[24][0.5in]
\end{multicols}

\newpage
\section{Grayscale}
\begin{multicols}{5}
\showgray[8][0.5in]
\end{multicols}


\newpage
\section{x11 Names}
\begin{multicols}{5}
\showaseq[0][0.5in]{x11}
\end{multicols}



\end{document}
1
  • Thank you very much for the addition.
    – alex
    Oct 6, 2022 at 15:24

You must log in to answer this question.

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