1

I want to include short code for in a single line that is marked by a grey background. Here is an example:

I want to include code of this form that is in the middle of the text.

  • Do you mean find the middle of a line and then mark it or just mark some text that may be in the middle ? – Hafid Boukhoulda Sep 26 '18 at 10:51
2

Here is an example built from the tcolorbox package. You can get all relevant information and customisation options from the well detailed manual

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{xparse}
\begin{document}
An example with the \tcboxverb{tcolorbox} package with its \tcboxverb{\tcboxverb} command from the \tcboxverb{xparse} library 
\end{document}

enter image description here

1

This is perhaps somewhat fragile, but works:

enter image description here

\documentclass{article}

\usepackage{xcolor}

\colorlet{codecolor}{black!30}
\newcommand{\codebox}[1]{%
  \colorbox{codecolor}{\ttfamily \detokenize{#1}}%
}

\begin{document}

I want to include \codebox{code of this form} that is in the middle of the text.

I want to include \codebox{code_ of^ this\ form} that is in the middle of the text.

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.