4

I want to highlight some code~ish thing in a report like this:

blahblahblah...Then you should use ./runprog to start up the program etc etc...

How can I do this?

4

1 Answer 1

9

Use the colorbox command from xcolor package:

\documentclass{article}

\usepackage{xcolor}
    \newcommand{\SEBox}[1]{\texttt{\colorbox{gray!14}{#1}}}

\begin{document}
     \SEBox{blahblah}
\end{document}

monospaced example text on a gray background

7
  • It works! Thank you! Could you kindly explain for me what is this command doing? Jun 8, 2015 at 6:40
  • 1
    \texttt changes font to typewriter style; \colorbox changes the text background color to 10% transparent gray (gray!10).
    – jak123
    Jun 8, 2015 at 6:42
  • What are [1] and {#1}? Jun 8, 2015 at 6:44
  • [1] number of arguments passed to the command, and #1 means use argument #1 here. For example, you can write \newcommand{\SEBox}[2][gray!10]{\texttt{\colorbox{#2}{#1}}} to be able to change the background color. Check this out: emerson.emory.edu/services/latex/latex_19.html
    – jak123
    Jun 8, 2015 at 6:46
  • 1
    @anetworknoobie You ought to read about command definitions etc. Just search things like "newcommand latex" on google and on this site and you'll find tons of resources about that. If you are using linux or mac be aware that you probably have texdoc installed. So if you want to learn about a certain package you can just launch from the terminal texdoc package-name to see its documentation (e.g. texdoc mathtools).
    – Bakuriu
    Jun 8, 2015 at 9:43

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.