根据 RGB 规范进行颜色合并

根据 RGB 规范进行颜色合并

利用该xcolor包,我们可以用多种方式定义颜色,例如使用标准名称,

\colorbox{red}{...}

合并颜色

\colorbox{red!25}{...}

\colorbox{red!25!blue}{...}

或者从 RGB 或 CYMK 值

\colorbox[rgb]{0.1,0.2,0.3}{...}

是否可以合并排队RGB 和合并方法?例如

\colorbox[rgb]{0.1,0.2,0.3 ! 25}{...} %invalid code

\colorbox{\color[rgb]{0.70,0.05,0.65}!25}{...} %also invalid

使给定的 RGB 颜色变浅。上下文是,对于给定的元素,我知道 RGB 值,但我想通过与白色合并使其变浅。

梅威瑟:

\documentclass[]{article}
\usepackage[]{xcolor}
\begin{document}
\colorbox[rgb]{0.70,0.05,0.65}{A} % this turns to be dark violet, how to get something like {violet!25}
\end{document}

答案1

当然可以。xcolor该包提供了非常复杂的混合颜色扩展语法(有关xcolor详细信息,请参阅文档的第 14-16 页):

\documentclass[]{article}
\usepackage[]{xcolor}
\begin{document}
\colorbox{rgb:red,0.70;green,0.05;blue,0.65}{A} % this turns to be dark violet, how to 

\colorbox{rgb:red!40,0.70;green!40,0.05;blue!40,0.65}{A}

\colorbox{rgb:red!10,0.70;green!10,0.05;blue!10,0.65}{A}
\end{document}

在此处输入图片描述

更多“在线”色调:

\documentclass{article}
\usepackage[]{xcolor}
\usepackage{pgffor}

\begin{document}
\noindent
\colorbox{rgb:red,0.70;green,0.05;blue,0.65}{A}\quad % this turns to be dark violet, how to 
\foreach \Valor in {90,80,...,10}
{%
  \colorbox{rgb:red!\Valor,0.70;green!\Valor,0.05;blue!\Valor,0.65}{A}\quad
}
\end{document}

在此处输入图片描述

事实上,你可以用这种方法产生许多变化,以及更复杂的混合,或者例如补码运算符-。一个小例子展示了你的初始颜色的“内联”变化:

\documentclass[]{article}
\usepackage[]{xcolor}
\begin{document}
\colorbox{rgb:red,0.70;green,0.05;blue,0.65}{A} % this turns to be dark violet, how to 

\colorbox{rgb:red!40,0.70;green!40,0.05;blue!40,0.65}{A}

\colorbox{rgb:red!10,0.70;green!10,0.05;blue!10,0.65}{A}

\colorbox{rgb:red!10!cyan,0.70;green!60!cyan,0.05;blue!10,0.65}{A}

\colorbox{rgb:-red!10!cyan,0.70;green!60!cyan,0.05;blue!10,0.65}{A}

\colorbox{rgb:red!10!cyan,0.70;-green!60!cyan,0.05;blue!10!orange,0.65}{A}

\colorbox{rgb:-red!10!cyan,0.70;-green!60!cyan,0.05;blue!10!orange,0.65}{A}
\end{document}

在此处输入图片描述

答案2

通常这是通过定义颜色来完成的第一的,之后您可以对其进行阴影处理(或合并):

在此处输入图片描述

\documentclass{article}
\usepackage{xcolor}
\definecolor{violet}{rgb}{0.70,0.05,0.65}
\begin{document}
\colorbox[rgb]{0.70,0.05,0.65}{A} % this turns to be dark violet, how to get something like {violet!25}

\colorbox{violet}{A}

\colorbox{violet!25}{A}
\end{document}

答案3

你可以定义一个包装器命令\rgbbox[<optional proportion>]{<rgb specification>}{<contents>},例如:

\documentclass{article}
\usepackage{xcolor}
\newcommand\rgbbox[3][100]{%
  \definecolor{rgbboxcolour}{rgb}{#2}%
  \colorbox{rgbboxcolour!#1}{#3}%
}
\begin{document}
\colorbox[rgb]{0.70,0.05,0.65}{A} % this turns to be dark violet, how to get something like {violet!25}

\rgbbox[25]{0.70,0.05,0.65}{B}

\rgbbox[50]{.25,.75,.75}{C}

\rgbbox{.25,.75,.75}{D}
\end{document}

演示

请注意,如果未指定可选参数,则不会得到混合,即第一个强制参数中给出的颜色的 100%。

相关内容