有人知道如何在列表中写出诸如总和、积分之类的数学符号吗?
\begin{lstlisting}
vl(i)= \sum\limits_{i=1}^N{Al(i,j)*xl(j)} ; i = 1,3
\end{lstlisting}
更新:最小示例
\documentclass{book}
\usepackage{xcolor}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[backgroundcolor=\color{blue!40},numbers=none,language=XML,mathescape=true]
!-----------------------------------------------------
$vl(i)=\sum\limits_{i=1}^N{Al(i,j)*xl(j)} ;\quad i = 1,3$
!-----------------------------------------------------
\end{lstlisting}
\end{document}
答案1
使用mathescape
代码
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[mathescape]
$vl(i)= \sum\limits_{i=1}^N{Al(i,j)*xl(j)} ;\quad i = 1,3$
\end{lstlisting}
\end{document}
输出
编辑
为了避免背景出现空白行,您可以尝试以下方法mdframed
:
\documentclass{book}
\usepackage{xcolor}
\usepackage{listings}
\usepackage[framemethod=TikZ]{mdframed}
\begin{document}
\begin{mdframed}[backgroundcolor=blue!40]
\begin{lstlisting}[numbers=none,language=XML,mathescape=true]
!-----------------------------------------------------
$vl(i)=\sum\limits_{i=1}^N{Al(i,j)*xl(j)} ;\quad i = 1,3$
!-----------------------------------------------------
\end{lstlisting}
\end{mdframed}
\end{document}
输出: