和
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
backgroundcolor=\color{gray},
emph={FMD},
emphstyle={\color{orange}},
emph={[2]RAW},
emphstyle={[2]\color{blue}}
}
\begin{document}
\begin{lstlisting}[caption={Caption with {\lstinline[emphstyle=\ttfamily,basicstyle=\ttfamily]+FMD+} and {\lstinline[emphstyle=\ttfamily,basicstyle=\ttfamily]+RAW+}}]
This line inclues FMD and RAW.
\end{lstlisting}
\end{document}
我明白了
当有多个级别的强调样式时,如何禁用标题中的突出显示?
答案1
\lstinline
在标题中使用这里没有意义:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
backgroundcolor=\color{gray},
emph={FMD},
emphstyle={\color{orange}},
emph={[2]RAW},
emphstyle={[2]\color{blue}}
}
\begin{document}
\begin{lstlisting}[caption={Caption with {\ttfamily FMD} and {\ttfamily RAW}}]
This line inclues FMD and RAW.
\end{lstlisting}
\begin{lstlisting}[caption={Caption with {\lstinline[emphstyle=\ttfamily,basicstyle=\ttfamily]+FMD+} and {\lstinline[emphstyle=\ttfamily,basicstyle=\ttfamily]+RAW+}}]
This line inclues FMD and RAW.
\end{lstlisting}
\end{document}
答案2
解决方案其实很简单:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
backgroundcolor=\color{gray},
emph={FMD},
emphstyle={\color{orange}},
emph={[2]RAW},
emphstyle={[2]\color{blue}}
}
\newcommand{\inline}[1]{\lstinline[emphstyle={\ttfamily},emphstyle={[2]\ttfamily},basicstyle=\ttfamily][#1[}
\begin{document}
\begin{lstlisting}[caption={Caption with \inline{FMD} and \inline{RAW}}]
This line inclues FMD and RAW.
\end{lstlisting}
\end{document}