请参阅下面的问题:
\documentclass{article}
\usepackage{listings}
\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline|var|. How can I visually set off
\lstinline|var| as something special without being too ridiculous?
\end{document}
当前输出作为演示:
如何更改内联列表而不更改显示列表的样式?
答案1
通常使用等宽字体(也许使用较小的字体大小)就足够了,这可以使用可选参数来完成,\lstinnline
或者更好的是,定义一个已经包含所需选项的短变体:
\documentclass{article}
\usepackage{listings}
\lstMakeShortInline[basicstyle=\small\ttfamily]|
\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline[basicstyle=\small\ttfamily]|var|. How can I visually set off
\lstinline[basicstyle=\small\ttfamily]|var| as something special without being too ridiculous?
Here is some text where I would like to talk about a particular
variable called |var|. How can I visually set off
|var| as something special without being too ridiculous?
\end{document}
当然,您还可以添加一些其他属性(例如颜色):
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstMakeShortInline[basicstyle=\small\ttfamily\color{cyan}]|
\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline[basicstyle=\small\ttfamily\color{cyan}]|var|. How can I visually set off
\lstinline[basicstyle=\small\ttfamily\color{cyan}]|var| as something special without being too ridiculous?
Here is some text where I would like to talk about a particular
variable called |var|. How can I visually set off
|var| as something special without being too ridiculous?
\end{document}
答案2
另一个选择是定义一种新样式,例如
\lstdefinestyle{inline}{%
basicstyle=\small\ttfamily\color{red}
}
并使用它来\lstinline
不管用来包围列表的字符是什么:
\lstinline[style=inline]|var|
\lstinline[style=inline]!var!
梅威瑟:
\documentclass{article}
\usepackage{listings,xcolor}
\lstdefinestyle{inline}{%
basicstyle=\small\ttfamily\color{red}
}
\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline[style=inline]|var|. How can I visually set off
\lstinline[style=inline]!var! as something special without being too ridiculous?
\end{document}
输出: