在清单中突出显示代码块 [英] Highlighting a Chunk of Code within a lstlisting
本文介绍了在清单中突出显示代码块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在lstlisting环境中有一堆代码.如何在环境中仅突出显示特定的代码块(彩色背景)?
I have a bunch of code in a lstlisting environment. How can I highlight (color background) just a particular chunk of code within the environment?
推荐答案
您可以在列表中使用\ colorbox和转义字符:
You can use \colorbox and an escape character inside your listing:
添加到您的序言
\usepackage{color}
\definecolor{light-gray}{gray}{0.80}
然后在文档中像这样使用它:
then use it like this in your document:
\begin{lstlisting}[escapechar=!]
def mult(m: Matrix[Int], n: Matrix[Int]) {
val p = !\colorbox{light-gray}{new MatrixInt}!(m.rows, n.cols)
}
\end{lstlisting}
这篇关于在清单中突出显示代码块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文