How can I make small, grey-highlighted code – words
just like this one in this sentence. Is it possible to put some math in these boxes later? I tried to use soul package but I didn't manage to change the colour.
[Tex/LaTex] Grey highlighted words
color
Best Answer
The command to change the colour of a highlight in
soul
is\sethlcolor{}
. Here's an MWE:You may encounter some trouble with mathematics in that the highlight does not expand vertically to fit the full height of your math; i.e. it looks like this:
A solution in this case would be to put your math into a Tikz node. The following code is an MWE in which I create a command
\tikzhl
that implements a highlight in this fashion:The result looks like this:
Note that this Tikz solution (unlike soul) does not support line breaks. See How to "highlight" text/formulas with tikz? for more on implementing highlights with Tikz.
If you want the background to be a lighter shade of grey, change
lightgray
toblack!10
. Varying the number10
between0
and100
will produce increasingly dark shades of grey.In the Tikz solution, you can vary the amount of 'padding' around the edge of your text with the
inner sep=
option thus: