2

I am trying to add some inline python code into my report with color in an box like following:

enter image description here

As you can see "matrix text is red coloured embedded in a box" I can add inline colour code using the following method:

CVXOPT extends the built-in Python objects with two matrix objects: a {\color{red}\texttt{matrix}} object for dense

Which produces the following output: enter image description here

It is almost perfect except a box around the code. How I can have a box around the code?

  • Hi, ya it is close to my requirement. Thank you. – Mohammad Saifullah Feb 7 '16 at 17:17
3

You can simply put it inside an \fbox{...}:

\documentclass[border=5pt]{standalone}
\usepackage{xcolor}

\newcommand{\pyobject}[1]{\fbox{\color{red}{\texttt{#1}}}}

\begin{document}

CVXOPT extends the built-in Python objects with two matrix objects: a \pyobject{matrix} object for dense

\end{document}

Output, square corners

Or, if you want rounded corners, use \ovalbox{...} from the fancybox package:

\documentclass[border=5pt]{standalone}
\usepackage{xcolor,fancybox}

\newcommand{\pyobject}[1]{\ovalbox{\color{red}{\texttt{#1}}}}

\begin{document}

CVXOPT extends the built-in Python objects with two matrix objects: a \pyobject{matrix} object for dense

\end{document}

Output, rounded corners

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.