为内联文本添加灰色背景

为内联文本添加灰色背景

我想like this在普通文本中为几个单词添加灰色背景?比如用\colorbox{yellow}{\lstinline{some text here}}灰色代替黄色。该怎么做?

答案1

正如您在问题中所写,您使用了\colorbox。由于第一个参数只是一个颜色名称,您需要将其交换yellowgray或其他定义的颜色之一xcolor(第一列是名称):

\definecolorset{rgb/hsb/cmyk/gray}{}{}%
 {red,1,0,0/0,1,1/0,1,1,0/.3;%
  green,0,1,0/.33333,1,1/1,0,1,0/.59;%
  blue,0,0,1/.66667,1,1/1,1,0,0/.11;%
  brown,.75,.5,.25/.083333,.66667,.75/0,.25,.5,.25/.5475;%
  lime,.75,1,0/.20833,1,1/.25,0,1,0/.815;%
  orange,1,.5,0/.083333,1,1/0,.5,1,0/.595;%
  pink,1,.75,.75/0,.25,1/0,.25,.25,0/.825;%
  purple,.75,0,.25/.94444,1,.75/0,.75,.5,.25/.2525;%
  teal,0,.5,.5/.5,1,.5/.5,0,0,.5/.35;%
  violet,.5,0,.5/.83333,1,.5/0,.5,0,.5/.205}%
\definecolorset{cmyk/rgb/hsb/gray}{}{}%
 {cyan,1,0,0,0/0,1,1/.5,1,1/.7;%
  magenta,0,1,0,0/1,0,1/.83333,1,1/.41;%
  yellow,0,0,1,0/1,1,0/.16667,1,1/.89;%
  olive,0,0,1,.5/.5,.5,0/.16667,1,.5/.39}
\definecolorset{gray/rgb/hsb/cmyk}{}{}%
 {black,0/0,0,0/0,0,0/0,0,0,1;%
  darkgray,.25/.25,.25,.25/0,0,.25/0,0,0,.75;%
  gray,.5/.5,.5,.5/0,0,.5/0,0,0,.5;%
  lightgray,.75/.75,.75,.75/0,0,.75/0,0,0,.25;%
  white,1/1,1,1/0,0,1/0,0,0,0}

例子:

\documentclass{article}

\usepackage{xcolor}


\begin{document}

werwe \colorbox{lightgray}{sdfASDF} wqerwqe

\end{document}

答案2

选项svgnames定义xcolor了多种灰度。此外,你还可以轻松混合颜色。以下是演示:

\documentclass{article}

\usepackage[svgnames]{xcolor}


\begin{document}

 \colorbox{lightgray}{sdfASDF} \medskip

 \colorbox{Gainsboro}{sdfASDF} \medskip

 \colorbox{Gainsboro!60!Lavender}{sdfASDF}\medskip

 \colorbox{WhiteSmoke}{sdfASDF} \medskip

 \colorbox{WhiteSmoke!70!Lavender}{sdfASDF}

\end{document} 

解释(适用于 2 种颜色):Gainsboro!60!Lavender表示 60% 的 Gainsboro 和 40% 的 Lavender。

Gainboro!70意味着 70% 的盖恩斯伯勒和 30% 的白人。

在此处输入图片描述

相关内容