\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}
\ExplSyntaxOn
\keys_define:nn { lyl/mycolorbox }
{
color .tl_set:N = \l__lyl_mycolorbox_color_tl,
text .tl_set:N = \l__lyl_mycolorbox_text_tl,
color .initial:n = red!40,
text .initial:n = some~text,
}
\NewDocumentCommand{\mycolorbox}{O{}}
{
\group_begin:
\keys_set:nn { lyl/mycolorbox } { #1 }
\colorbox{\l__lyl_mycolorbox_color_tl}{\l__lyl_mycolorbox_text_tl}
\group_end:
}
\ExplSyntaxOff
\begin{document}
\mycolorbox[color=blue!20]
\mycolorbox[text=This is a practice. Default colour.]
\mycolorbox[color=blue!20, text=This is a practice.]
\mycolorbox[text=\strut]
: with strut
\mycolorbox[text=\strut\ ]
: strut with space
\mycolorbox[text=\strut\ ,color=red]
\mycolorbox[text=\strut\ ,color=blue]
\mycolorbox[text=\strut\ ,color=green]
\mycolorbox[text=\strut\ ,color=yellow]
: set of boxes
\setlength{\fboxsep}{5pt}
\mycolorbox[text=\strut\ ,color=red]
\mycolorbox[text=\strut\ ,color=blue]
\mycolorbox[text=\strut\ ,color=green]
\mycolorbox[text=\strut\ ,color=yellow]
: fboxsep=5pt
\mycolorbox[text=\strut R ,color=red]%
\mycolorbox[text=\strut\textcolor{white}{B} ,color=blue]%
\mycolorbox[text=\strut G ,color=green]%
\mycolorbox[text=\strut Y ,color=yellow]
: no spaces
\fbox{%
\mycolorbox[text=\strut R ,color=red]%
\mycolorbox[text=\strut\textcolor{white}{B} ,color=blue]%
\mycolorbox[text=\strut G ,color=green]%
\mycolorbox[text=\strut Y ,color=yellow]%
}
: inside fbox
\fcolorbox{violet}{blue!20}{%
\mycolorbox[text=\strut R ,color=red]%
\mycolorbox[text=\strut\textcolor{white}{B} ,color=blue]%
\mycolorbox[text=\strut G ,color=green]%
\mycolorbox[text=\strut Y ,color=yellow]%
}
: inside fcolorbox
\setlength{\fboxrule}{2pt}
\fcolorbox{violet}{blue!20}{%
\mycolorbox[text=\strut R ,color=red]%
\mycolorbox[text=\strut\textcolor{white}{B} ,color=blue]%
\mycolorbox[text=\strut G ,color=green]%
\mycolorbox[text=\strut Y ,color=yellow]%
}
: fboxrule = 2pt
\fcolorbox{violet}{blue!20}{%
\mycolorbox[text=\strut\sffamily red ,color=red]%
\mycolorbox[text=\strut\sffamily\textcolor{white}{blue} ,color=blue]%
\mycolorbox[text=\strut\sffamily green ,color=green]%
\mycolorbox[text=\strut\sffamily yellow ,color=yellow]%
}
\end{document}