Hi i am trying to add an inline code block in a Latex document. I know how to add a separate code block using lstlisting
but i want to instead add an inline code block. I am attaching the screenshot of output that i am expecting .As you can see in the same line a code block is added which contains the expression print(g)
. I want something like that. So that it should be customizable that is the background color of the box, width and height of the box, border width etc. Also the text of the code inside that inline code block should be customizable as well. Is there a way to achieve this in Latex? Below is the screenshot.
[Tex/LaTex] Insert inline code block in Latex document
codeinline()listings
Best Answer
It is possible, and here is one way do it. (This code is an excerpt from a package I maintain and for some reason,
realboxes
must be loaded afterxcolor
whereas in my package, which loads several other packages, that is not the case and I'm not yet sure why.)The background color is an argument to the
\Colorbox
command.UPDATE:
Here is a variant showing how to use
tcolorbox
to achieve your, hopefully, desired results. Play with the options!