1

有没有一种简单的方法可以让lstlisting环境中的完整代码加下划线?我目前的解决方案看起来像这样,但我对此并不满意。

\begin{lstlisting}[mathescape]
   $\ul{if(gt(x1, 0)) then} $
   ...
\end{lstlisting}

感谢您的任何提示。

4

2 回答 2

1

根据用户指南中的第 5 页(在此处找到):

\lstset{keywordstyle=\underbar} 
于 2010-05-02T18:46:45.470 回答
0

如果您想在整行下划线(而不仅仅是关键字),我能想到的最佳解决方案是按照以下几行做一些事情:

\usepackage{listings}

\newcommand{\lstul}[1]{\underline{\mbox{\tt #1}}}

\begin{document}

\begin{lstlisting}[mathescape]
  $\lstul{if condition}$
      $\lstul{statement 1}$
  $\lstul{statement 2}$
  ...
\end{lstlisting}


\end{document}
于 2010-05-02T18:52:14.527 回答