5

I want to make several words with a grey background like this within normal text? Like with \colorbox{yellow}{\lstinline{some text here}} but grey instead of yellow. How to do that?

chrisma
  • 1,239
vasili111
  • 377
  • 2
    Have you tried replacing yellow with gray, i.e. \colorbox{gray}{...}? You could also define your own, lighter gray color (e.g. \definecolor{light-gray}{gray}{0.89}). – chrisma Aug 28 '18 at 14:38
  • 2
    Simply with \colorbox{grey}{ ... }. Or did I misunderstand? – Bernard Aug 28 '18 at 14:38
  • @chrisma This works "\colorbox{yellow}{sadef}". This "\colorbox{gray}{sdfASDF}" gives error "Undefined color gray'. \colorbox{gray}{sdfASDF}". This "\colorbox{grey}{sdfASDF}" gives error "Undefined colorgrey'. \colorbox{grey}{sdfASDF}". – vasili111 Aug 28 '18 at 14:46
  • @chrisma This works "\colorbox{yellow}{sadef}". This "\colorbox{gray}{sdfASDF}" gives error "Undefined color gray'. \colorbox{gray}{sdfASDF}". This "\colorbox{grey}{sdfASDF}" gives error "Undefined colorgrey'. \colorbox{grey}{sdfASDF}". – vasili111 Aug 28 '18 at 14:46
  • Sorry cannot format comment properly. – vasili111 Aug 28 '18 at 14:49
  • 1
    Did you load xcolor? – Bernard Aug 28 '18 at 14:51
  • @chrisma Why did you delete your answer? It was fine! – campa Aug 28 '18 at 14:59
  • @Bernard I added xcolor and it works with \colorbox{gray}{sdfASDF}. How can I get more light grey? \colorbox{light-gray}{sdfASDF}and \colorbox{light-grey}{sdfASDF} does not works. – vasili111 Aug 28 '18 at 15:00
  • Use lightgray or define an own color (see documentation on how to do that). – TeXnician Aug 28 '18 at 15:14
  • @TeXnician \colorbox{lightgrey}{sdfASDF} does not works too. – vasili111 Aug 28 '18 at 15:16
  • That's why I wrote lightgray. a instead of e. – TeXnician Aug 28 '18 at 15:18
  • @TeXnician That works. Thank you. Write the answer if you want and I will except it – vasili111 Aug 28 '18 at 15:20
  • If you load xcolor with option svgnames, you have access to other shades of grey, such as Gainsboro or WhiteSmoke. Also you can mix colours. – Bernard Aug 28 '18 at 15:29
  • @Bernard Thank you. That works. If you wish you can make an answer and I will upvote. If you will not I will add the answer with your suggestion later. – vasili111 Aug 28 '18 at 15:42

2 Answers2

8

The svgnames option of xcolor defines a number of shades of grey. Furthermore, you can mix colours easily. Here's a demo:

\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}

Explanation (valid for 2 colours): Gainsboro!60!Lavender means 60 % of Gainsboro and 40% of Lavender.

Gainboro!70 would mean 70 % of Gainsboro and 30 % of white.

enter image description here

Bernard
  • 271,350
6

As you write in your question you use \colorbox. As the first argument is simply a color name you need to exchange yellow for gray or one of the other defined colors from xcolor (first column is name):

\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}

Example:

\documentclass{article}

\usepackage{xcolor}


\begin{document}

werwe \colorbox{lightgray}{sdfASDF} wqerwqe

\end{document}
vasili111
  • 377
TeXnician
  • 33,589