Latex 中的內嵌 python 程式碼

Latex 中的內嵌 python 程式碼

我正在嘗試將一些內聯 python 程式碼添加到我的報告中,並在如下框中使用顏色:

在此輸入影像描述

正如您所看到的“矩陣文字是嵌入在框中的紅色”我可以使用以下方法添加內聯顏色代碼:

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

產生以下輸出: 在此輸入影像描述

除了程式碼周圍有一個框之外,它幾乎是完美的。我怎樣才能在程式碼周圍有一個框?

答案1

您可以簡單地將其放入\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}

輸出,方角

或者,如果您想要圓角,請\ovalbox{...}使用fancybox包裹:

\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}

輸出,圓角

相關內容